lol

nix-channel: do not set empty nix-path when disabling channels

An empty nix-path in nix.conf will disable NIX_PATH environment variable
entirely, which is not necessarily implied by users who want to disable
nix channels. NIX_PATH also has some usages in tools like nixos-rebuild
or just as user aliases.

That change is surprising and debatable, and also caused breakages in
nixpkgs-review and user configs.

See:
- https://github.com/NixOS/nixpkgs/pull/242098/files#r1269891427
- https://github.com/Mic92/nixpkgs-review/issues/343
- https://github.com/NixOS/nix/pull/10998

Co-authored-by: oxalica <oxalicc@pm.me>

+22 -2
+22 -2
nixos/modules/config/nix-channel.nix
··· 12 12 mkDefault 13 13 mkIf 14 14 mkOption 15 + stringAfter 15 16 types 16 17 ; 17 18 ··· 94 95 NIX_PATH = cfg.nixPath; 95 96 }; 96 97 97 - nix.settings.nix-path = mkIf (! cfg.channel.enable) (mkDefault ""); 98 - 99 98 systemd.tmpfiles.rules = lib.mkIf cfg.channel.enable [ 100 99 ''f /root/.nix-channels - - - - ${config.system.defaultChannel} nixos\n'' 101 100 ]; 101 + 102 + system.activationScripts.no-nix-channel = mkIf (!cfg.channel.enable) 103 + (stringAfter [ "etc" "users" ] '' 104 + if [ -e "/root/.nix-defexpr/channels" ]; then 105 + echo "WARNING: /root/.nix-defexpr/channels exists, but channels have been disabled." 1>&2 106 + echo "Due to https://github.com/NixOS/nix/issues/9574, Nix may still use these channels when NIX_PATH is unset." 1>&2 107 + echo "Delete the above directory to prevent this." 1>&2 108 + fi 109 + if [ -e "/nix/var/nix/profiles/per-user/root/channels" ]; then 110 + echo "WARNING: /nix/var/nix/profiles/per-user/root/channels exists, but channels have been disabled." 1>&2 111 + echo "Due to https://github.com/NixOS/nix/issues/9574, Nix may still use these channels when NIX_PATH is unset." 1>&2 112 + echo "Delete the above directory to prevent this." 1>&2 113 + fi 114 + getent passwd | while IFS=: read -r _ _ _ _ _ home _ ; do 115 + if [ -n "$home" -a -e "$home/.nix-defexpr/channels" ]; then 116 + echo "WARNING: $home/.nix-defexpr/channels exists, but channels have been disabled." 1>&2 117 + echo "Due to https://github.com/NixOS/nix/issues/9574, Nix may still use these channels when NIX_PATH is unset." 1>&2 118 + echo "Delete the above directory to prevent this." 1>&2 119 + fi 120 + done 121 + ''); 102 122 }; 103 123 }