nixos/nix-channel: Take care of NIX_PATH's non-empty default when disabled

This commit is contained in:
Robert Hensing 2023-07-07 23:12:39 +02:00
parent d00e242b80
commit 61afc4d166
2 changed files with 18 additions and 1 deletions

View File

@ -9,6 +9,7 @@
{ config, lib, ... }:
let
inherit (lib)
mkDefault
mkIf
mkOption
stringAfter
@ -88,10 +89,14 @@ in
rm $out/bin/nix-channel
'';
environment.sessionVariables = mkIf (cfg.nixPath != []) {
# NIX_PATH has a non-empty default according to Nix docs, so we don't unset
# it when empty.
environment.sessionVariables = {
NIX_PATH = cfg.nixPath;
};
nix.settings.nix-path = mkIf (! cfg.channel.enable) (mkDefault "");
system.activationScripts.nix-channel = mkIf cfg.channel.enable
(stringAfter [ "etc" "users" ] ''
# Subscribe the root user to the NixOS channel by default.

View File

@ -338,6 +338,18 @@ let
with subtest("nix-channel command is not available anymore"):
machine.succeed("! which nix-channel")
# Note that the channel profile is still present on disk, but configured
# not to be used.
with subtest("builtins.nixPath is now empty"):
machine.succeed("""
[[ "[ ]" == "$(nix-instantiate builtins.nixPath --eval --expr)" ]]
""")
with subtest("<nixpkgs> does not resolve"):
machine.succeed("""
! nix-instantiate '<nixpkgs>' --eval --expr
""")
with subtest("Evaluate flake config in fresh env without nix-channel"):
machine.succeed("nixos-rebuild switch --flake /root/my-config#xyz")