nixos/nix-channel: Take care of NIX_PATH's non-empty default when disabled
This commit is contained in:
parent
d00e242b80
commit
61afc4d166
@ -9,6 +9,7 @@
|
|||||||
{ config, lib, ... }:
|
{ config, lib, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib)
|
inherit (lib)
|
||||||
|
mkDefault
|
||||||
mkIf
|
mkIf
|
||||||
mkOption
|
mkOption
|
||||||
stringAfter
|
stringAfter
|
||||||
@ -88,10 +89,14 @@ in
|
|||||||
rm $out/bin/nix-channel
|
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_PATH = cfg.nixPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
nix.settings.nix-path = mkIf (! cfg.channel.enable) (mkDefault "");
|
||||||
|
|
||||||
system.activationScripts.nix-channel = mkIf cfg.channel.enable
|
system.activationScripts.nix-channel = mkIf cfg.channel.enable
|
||||||
(stringAfter [ "etc" "users" ] ''
|
(stringAfter [ "etc" "users" ] ''
|
||||||
# Subscribe the root user to the NixOS channel by default.
|
# Subscribe the root user to the NixOS channel by default.
|
||||||
|
@ -338,6 +338,18 @@ let
|
|||||||
with subtest("nix-channel command is not available anymore"):
|
with subtest("nix-channel command is not available anymore"):
|
||||||
machine.succeed("! which nix-channel")
|
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"):
|
with subtest("Evaluate flake config in fresh env without nix-channel"):
|
||||||
machine.succeed("nixos-rebuild switch --flake /root/my-config#xyz")
|
machine.succeed("nixos-rebuild switch --flake /root/my-config#xyz")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user