Loading doc/build-helpers/testers.chapter.md +49 −0 Original line number Diff line number Diff line Loading @@ -116,6 +116,55 @@ It has two modes: : The `lychee` package to use. ## `shellcheck` {#tester-shellcheck} Runs files through `shellcheck`, a static analysis tool for shell scripts. :::{.example #ex-shellcheck} # Run `testers.shellcheck` A single script ```nix testers.shellcheck { name = "shellcheck"; src = ./script.sh; } ``` Multiple files ```nix let inherit (lib) fileset; in testers.shellcheck { name = "shellcheck"; src = fileset.toSource { root = ./.; fileset = fileset.unions [ ./lib.sh ./nixbsd-activate ]; }; } ``` ::: ### Inputs {#tester-shellcheck-inputs} [`src` (path or string)]{#tester-shellcheck-param-src} : The path to the shell script(s) to check. This can be a single file or a directory containing shell files. All files in `src` will be checked, so you may want to provide `fileset`-based source instead of a whole directory. ### Return value {#tester-shellcheck-return} A derivation that runs `shellcheck` on the given script(s). The build will fail if `shellcheck` finds any issues. ## `testVersion` {#tester-testVersion} Checks that the output from running a command contains the specified version string in it as a whole word. Loading nixos/modules/config/nix-channel.nix +4 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ let mkDefault mkIf mkOption stringAfter types ; Loading Loading @@ -97,5 +98,8 @@ in systemd.tmpfiles.rules = lib.mkIf cfg.channel.enable [ ''f /root/.nix-channels - - - - ${config.system.defaultChannel} nixos\n'' ]; system.activationScripts.no-nix-channel = mkIf (!cfg.channel.enable) (stringAfter [ "etc" "users" ] (builtins.readFile ./nix-channel/activation-check.sh)); }; } nixos/modules/config/nix-channel/activation-check.sh 0 → 100644 +21 −0 Original line number Diff line number Diff line # shellcheck shell=bash explainChannelWarning=0 if [[ -e "/root/.nix-defexpr/channels" ]]; then warn '/root/.nix-defexpr/channels exists, but channels have been disabled.' explainChannelWarning=1 fi if [[ -e "/nix/var/nix/profiles/per-user/root/channels" ]]; then warn "/nix/var/nix/profiles/per-user/root/channels exists, but channels have been disabled." explainChannelWarning=1 fi while IFS=: read -r _ _ _ _ _ home _ ; do if [[ -n "$home" && -e "$home/.nix-defexpr/channels" ]]; then warn "$home/.nix-defexpr/channels exists, but channels have been disabled." 1>&2 explainChannelWarning=1 fi done < <(getent passwd) if [[ $explainChannelWarning -eq 1 ]]; then echo "Due to https://github.com/NixOS/nix/issues/9574, Nix may still use these channels when NIX_PATH is unset." 1>&2 echo "Delete the above directory or directories to prevent this." 1>&2 fi nixos/modules/config/nix-channel/test.nix 0 → 100644 +19 −0 Original line number Diff line number Diff line # Run: # nix-build -A nixosTests.nix-channel { lib, testers }: let inherit (lib) fileset; runShellcheck = testers.shellcheck { src = fileset.toSource { root = ./.; fileset = fileset.unions [ ./activation-check.sh ]; }; }; in lib.recurseIntoAttrs { inherit runShellcheck; } nixos/modules/system/activation/activation-script.nix +2 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,8 @@ let '' #!${pkgs.runtimeShell} source ${./lib/lib.sh} systemConfig='@out@' export PATH=/empty Loading Loading
doc/build-helpers/testers.chapter.md +49 −0 Original line number Diff line number Diff line Loading @@ -116,6 +116,55 @@ It has two modes: : The `lychee` package to use. ## `shellcheck` {#tester-shellcheck} Runs files through `shellcheck`, a static analysis tool for shell scripts. :::{.example #ex-shellcheck} # Run `testers.shellcheck` A single script ```nix testers.shellcheck { name = "shellcheck"; src = ./script.sh; } ``` Multiple files ```nix let inherit (lib) fileset; in testers.shellcheck { name = "shellcheck"; src = fileset.toSource { root = ./.; fileset = fileset.unions [ ./lib.sh ./nixbsd-activate ]; }; } ``` ::: ### Inputs {#tester-shellcheck-inputs} [`src` (path or string)]{#tester-shellcheck-param-src} : The path to the shell script(s) to check. This can be a single file or a directory containing shell files. All files in `src` will be checked, so you may want to provide `fileset`-based source instead of a whole directory. ### Return value {#tester-shellcheck-return} A derivation that runs `shellcheck` on the given script(s). The build will fail if `shellcheck` finds any issues. ## `testVersion` {#tester-testVersion} Checks that the output from running a command contains the specified version string in it as a whole word. Loading
nixos/modules/config/nix-channel.nix +4 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ let mkDefault mkIf mkOption stringAfter types ; Loading Loading @@ -97,5 +98,8 @@ in systemd.tmpfiles.rules = lib.mkIf cfg.channel.enable [ ''f /root/.nix-channels - - - - ${config.system.defaultChannel} nixos\n'' ]; system.activationScripts.no-nix-channel = mkIf (!cfg.channel.enable) (stringAfter [ "etc" "users" ] (builtins.readFile ./nix-channel/activation-check.sh)); }; }
nixos/modules/config/nix-channel/activation-check.sh 0 → 100644 +21 −0 Original line number Diff line number Diff line # shellcheck shell=bash explainChannelWarning=0 if [[ -e "/root/.nix-defexpr/channels" ]]; then warn '/root/.nix-defexpr/channels exists, but channels have been disabled.' explainChannelWarning=1 fi if [[ -e "/nix/var/nix/profiles/per-user/root/channels" ]]; then warn "/nix/var/nix/profiles/per-user/root/channels exists, but channels have been disabled." explainChannelWarning=1 fi while IFS=: read -r _ _ _ _ _ home _ ; do if [[ -n "$home" && -e "$home/.nix-defexpr/channels" ]]; then warn "$home/.nix-defexpr/channels exists, but channels have been disabled." 1>&2 explainChannelWarning=1 fi done < <(getent passwd) if [[ $explainChannelWarning -eq 1 ]]; then echo "Due to https://github.com/NixOS/nix/issues/9574, Nix may still use these channels when NIX_PATH is unset." 1>&2 echo "Delete the above directory or directories to prevent this." 1>&2 fi
nixos/modules/config/nix-channel/test.nix 0 → 100644 +19 −0 Original line number Diff line number Diff line # Run: # nix-build -A nixosTests.nix-channel { lib, testers }: let inherit (lib) fileset; runShellcheck = testers.shellcheck { src = fileset.toSource { root = ./.; fileset = fileset.unions [ ./activation-check.sh ]; }; }; in lib.recurseIntoAttrs { inherit runShellcheck; }
nixos/modules/system/activation/activation-script.nix +2 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,8 @@ let '' #!${pkgs.runtimeShell} source ${./lib/lib.sh} systemConfig='@out@' export PATH=/empty Loading