Re: [PATCH 2/2] release.nix: run shellcheck on build scripts

Henri Rosten
2022-11-10T13:40:28Z

On Thu, Nov 10, 2022 at 11:22:20AM +0000, Alyssa Ross wrote:
> This will make the binary cache build (which I expect to become more
> CI-like over time) fail if shellcheck doesn't pass on any shell
> scripts found in the tree. This will help ensure we are sticking to
> POSIX shell features and following shell scripting best practices.
>
> At present, only scripts with names ending in ".sh" are processed, as
> we don't have any others, and discovering extensionless scripts would
> be quite a bit more complex. We can worry about that when the time
> comes.
>
> Signed-off-by: Alyssa Ross <alyssa.ross@unikie.com>

Reviewed-by: Henri Rosten <henri.rosten@unikie.com>

> ---
> nix/checks.nix | 24 ++++++++++++++++++++++++
> release.nix | 2 ++
> 2 files changed, 26 insertions(+)
> create mode 100644 nix/checks.nix
>
> diff --git a/nix/checks.nix b/nix/checks.nix
> new file mode 100644
> index 0000000..9eb261f
> --- /dev/null
> +++ b/nix/checks.nix
> @@ -0,0 +1,24 @@
> +# SPDX-License-Identifier: MIT
> +# SPDX-FileCopyrightText: 2022 Unikie
> +
> +{ config ? import ../nix/eval-config.nix {} }:
> +
> +{
> + recurseForDerivations = true;
> +
> + shellcheck = config.pkgs.callPackage (
> + { lib, runCommand, shellcheck }:
> + runCommand "spectrum-shellcheck" {
> + src = lib.cleanSourceWith {
> + filter = path: type:
> + type == "directory" || builtins.match ''.*[^/]\.sh'' path != null;
> + src = lib.cleanSource ../.;
> + };
> +
> + nativeBuildInputs = [ shellcheck ];
> + } ''
> + shellcheck $src/**/*.sh
> + touch $out
> + ''
> + ) {};
> +}
> diff --git a/release.nix b/release.nix
> index 91a843b..3ecf8a7 100644
> --- a/release.nix
> +++ b/release.nix
> @@ -12,5 +12,7 @@
> {
> doc = import ./Documentation { inherit config; };
>
> + checks = import nix/checks.nix { inherit config; };
> +
> combined = import img/combined/run-vm.nix { inherit config; };
> }
> --
> 2.35.1
>