Skip to content

Commit

Permalink
nixos/nix-channel: Take care of NIX_PATH's non-empty default when dis…
Browse files Browse the repository at this point in the history
…abled
  • Loading branch information
roberth committed Jul 7, 2023
1 parent d00e242 commit 61afc4d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion nixos/modules/config/nix-channel.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{ config, lib, ... }:
let
inherit (lib)
mkDefault
mkIf
mkOption
stringAfter
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions nixos/tests/installer.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 61afc4d

Please sign in to comment.