nixos/nix: move nix.nixPath into nix.settings.nix-path

This removes some confusion when setting nix.settings.nix-path to a custom value,
disabling channels and ending up with an empty NIX_PATH.
This is important since nix 2.24 fixed NIX_PATH not overwriting the
nix-path setting.
This commit is contained in:
Sandro Jäckel
2024-12-13 14:48:09 +01:00
parent 350f97c0d7
commit 4dfb033345
3 changed files with 13 additions and 8 deletions

View File

@@ -42,7 +42,7 @@ in
};
};
nixPath = mkOption {
settings.nix-path = mkOption {
type = types.listOf types.str;
default =
if cfg.channel.enable then
@@ -80,8 +80,11 @@ in
};
};
config = mkIf cfg.enable {
imports = [
(lib.mkRenamedOptionModule [ "nix" "nixPath" ] [ "nix" "settings" "nix-path" ])
];
config = mkIf cfg.enable {
environment.extraInit = mkIf cfg.channel.enable ''
if [ -e "$HOME/.nix-defexpr/channels" ]; then
export NIX_PATH="$HOME/.nix-defexpr/channels''${NIX_PATH:+:$NIX_PATH}"
@@ -95,7 +98,7 @@ in
# 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.settings.nix-path;
};
systemd.tmpfiles.rules = lib.mkIf cfg.channel.enable [

View File

@@ -102,7 +102,7 @@ in
# because we would need some kind of evil shim taking the *calling* flake's self path,
# perhaps, to ever make that work (in order to know where the Nix expr for the system came
# from and how to call it).
nix.nixPath = lib.mkDefault (
nix.settings.nix-path = lib.mkDefault (
[ "nixpkgs=flake:nixpkgs" ]
++ lib.optional config.nix.channel.enable "/nix/var/nix/profiles/per-user/root/channels"
);

View File

@@ -12,10 +12,12 @@ in
{
virtualisation.writableStore = true;
system.extraDependencies = [ (pkgs.runCommand "deps" { } "mkdir $out").inputDerivation ];
nix.nixPath = [ "nixpkgs=${../../..}" ];
nix.settings.substituters = lib.mkForce [ ];
nix.settings.system-features = [ "supported-feature" ];
nix.settings.experimental-features = [ "nix-command" ];
nix.settings = {
experimental-features = [ "nix-command" ];
nix-path = [ "nixpkgs=${../../..}" ];
substituters = lib.mkForce [ ];
system-features = [ "supported-feature" ];
};
nix.enable = true; # disabled by default. See all-tests.nix / tag(no-nix-by-default)
programs.nix-required-mounts.enable = true;
programs.nix-required-mounts.allowedPatterns.supported-feature = {