nixos/nix-channel.nix: shellcheck and fix the activation check

Changed files
+42 -21
nixos
modules
tests
+1 -21
nixos/modules/config/nix-channel.nix
···
];
system.activationScripts.no-nix-channel = mkIf (!cfg.channel.enable)
-
(stringAfter [ "etc" "users" ] ''
-
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
-
getent passwd | while IFS=: read -r _ _ _ _ _ home _ ; do
-
if [ -n "$home" -a -e "$home/.nix-defexpr/channels" ]; then
-
warn "$home/.nix-defexpr/channels exists, but channels have been disabled." 1>&2
-
explainChannelWarning=1
-
fi
-
done
-
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
-
'');
+
(stringAfter [ "etc" "users" ] (builtins.readFile ./nix-channel/activation-check.sh));
};
}
+21
nixos/modules/config/nix-channel/activation-check.sh
···
+
# 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
+19
nixos/modules/config/nix-channel/test.nix
···
+
# 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;
+
}
+1
nixos/tests/all-tests.nix
···
nbd = handleTest ./nbd.nix {};
ncdns = handleTest ./ncdns.nix {};
ndppd = handleTest ./ndppd.nix {};
+
nix-channel = pkgs.callPackage ../modules/config/nix-channel/test.nix { };
nebula = handleTest ./nebula.nix {};
netbird = handleTest ./netbird.nix {};
nimdow = handleTest ./nimdow.nix {};