diff --git a/nixos/modules/config/nix-channel.nix b/nixos/modules/config/nix-channel.nix index 515c3795a9fe..630474f70efe 100644 --- a/nixos/modules/config/nix-channel.nix +++ b/nixos/modules/config/nix-channel.nix @@ -11,7 +11,6 @@ let inherit (lib) mkIf mkOption - stringAfter types ; @@ -98,8 +97,8 @@ in ''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) + system.preSwitchChecks.no-nix-channel = mkIf (!cfg.channel.enable) ( + builtins.readFile ./nix-channel/pre-switch-check.sh ); }; } diff --git a/nixos/modules/config/nix-channel/activation-check.sh b/nixos/modules/config/nix-channel/pre-switch-check.sh similarity index 78% rename from nixos/modules/config/nix-channel/activation-check.sh rename to nixos/modules/config/nix-channel/pre-switch-check.sh index 42b1b712d702..b108244b07d3 100644 --- a/nixos/modules/config/nix-channel/activation-check.sh +++ b/nixos/modules/config/nix-channel/pre-switch-check.sh @@ -1,4 +1,6 @@ -# shellcheck shell=bash +warn() { + printf "\033[1;35mwarning:\033[0m %s\n" "$*" >&2 +} explainChannelWarning=0 if [[ -e "/root/.nix-defexpr/channels" ]]; then @@ -11,11 +13,13 @@ if [[ -e "/nix/var/nix/profiles/per-user/root/channels" ]]; then 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 + warn "$home/.nix-defexpr/channels exists, but channels have been disabled." 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 + echo "Due to https://github.com/NixOS/nix/issues/9574, Nix may still use these channels when NIX_PATH is unset." >&2 + echo "Delete the above directory or directories to prevent this." >&2 fi +# This check is informational only and must never block a switch. +true diff --git a/nixos/modules/config/nix-channel/test.nix b/nixos/modules/config/nix-channel/test.nix deleted file mode 100644 index 4692e01f12b1..000000000000 --- a/nixos/modules/config/nix-channel/test.nix +++ /dev/null @@ -1,20 +0,0 @@ -# Run: -# nix-build -A nixosTests.nix-channel -{ lib, testers }: -let - inherit (lib) fileset; - - runShellcheck = testers.shellcheck { - name = "activation-check"; - src = fileset.toSource { - root = ./.; - fileset = fileset.unions [ - ./activation-check.sh - ]; - }; - }; - -in -lib.recurseIntoAttrs { - inherit runShellcheck; -} diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 1dea04b0c19a..fa2faafc5054 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -1122,7 +1122,6 @@ in nimdow = runTest ./nimdow.nix; nipap = runTest ./web-apps/nipap.nix; nitter = runTest ./nitter.nix; - nix-channel = pkgs.callPackage ../modules/config/nix-channel/test.nix { }; nix-config = runTest ./nix-config.nix; nix-daemon-firewall = runTest ./nix-daemon-firewall.nix; nix-daemon-unprivileged = runTest ./nix-daemon-unprivileged.nix;