diff --git a/nixos/modules/config/nix-channel.nix b/nixos/modules/config/nix-channel.nix index 6498ce6c469c..772831ab6d17 100644 --- a/nixos/modules/config/nix-channel.nix +++ b/nixos/modules/config/nix-channel.nix @@ -12,6 +12,7 @@ let mkDefault mkIf mkOption + stringAfter types ; @@ -94,10 +95,29 @@ in NIX_PATH = cfg.nixPath; }; - nix.settings.nix-path = mkIf (! cfg.channel.enable) (mkDefault ""); - 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" ] '' + if [ -e "/root/.nix-defexpr/channels" ]; then + echo "WARNING: /root/.nix-defexpr/channels exists, but channels have been disabled." 1>&2 + 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 to prevent this." 1>&2 + fi + if [ -e "/nix/var/nix/profiles/per-user/root/channels" ]; then + echo "WARNING: /nix/var/nix/profiles/per-user/root/channels exists, but channels have been disabled." 1>&2 + 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 to prevent this." 1>&2 + fi + getent passwd | while IFS=: read -r _ _ _ _ _ home _ ; do + if [ -n "$home" -a -e "$home/.nix-defexpr/channels" ]; then + echo "WARNING: $home/.nix-defexpr/channels exists, but channels have been disabled." 1>&2 + 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 to prevent this." 1>&2 + fi + done + ''); }; }