nix: add a declarative alternative to Nix channels (#4031)
* nix: add options 'nixPath' and 'keepOldNixPath'
By default, the system value for $NIX_PATH is kept as a fallback.
To completely override the system value for $NIX_PATH:
nix.keepOldNixPath = false;
* nix: add more tests
* nix: add a declarative alternative to Nix channels
This adds a new option, 'nix.channels'. It's the Nix channels equivalent
of the 'nix.registry' option, and compatible with pre-Flake Nix tooling
including nix-env and nix-shell. Like 'nix.registry', this option is
useful for pinning Nix channels.
Channels defined in the new option can coexist with channels introduced
through the nix-channel command. If the same channel exists in both, the
one from Home Manager will be prioritized.
* nix: add news entry
* nix: make channels respect use-xdg-base-directories
* nix: remove 'with lib;'
---------
Co-authored-by: Michael Hoang <enzime@users.noreply.github.com>
This commit is contained in:
parent
892f76bd0a
commit
8d5e27b480
8 changed files with 172 additions and 2 deletions
|
|
@ -2,4 +2,7 @@
|
|||
nix-empty-settings = ./empty-settings.nix;
|
||||
nix-example-settings = ./example-settings.nix;
|
||||
nix-example-registry = ./example-registry.nix;
|
||||
nix-keep-old-nix-path = ./keep-old-nix-path.nix;
|
||||
nix-example-channels = ./example-channels.nix;
|
||||
nix-example-channels-xdg = ./example-channels-xdg.nix;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ with lib;
|
|||
|
||||
nmt.script = ''
|
||||
assertPathNotExists home-files/.config/nix
|
||||
assertPathNotExists home-files/.nix-defexpr/50-home-manager
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
|
|||
29
tests/modules/misc/nix/example-channels-xdg.nix
Normal file
29
tests/modules/misc/nix/example-channels-xdg.nix
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{ lib, config, pkgs, ... }:
|
||||
|
||||
let
|
||||
exampleChannel = pkgs.writeTextDir "default.nix" ''
|
||||
{ pkgs ? import <nixpkgs> { } }:
|
||||
|
||||
{
|
||||
example = pkgs.emptyDirectory;
|
||||
}
|
||||
'';
|
||||
in {
|
||||
config = {
|
||||
nix = {
|
||||
package = config.lib.test.mkStubPackage {
|
||||
version = lib.getVersion pkgs.nixVersions.stable;
|
||||
};
|
||||
channels.example = exampleChannel;
|
||||
settings.use-xdg-base-directories = true;
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertFileContains home-path/etc/profile.d/hm-session-vars.sh \
|
||||
'export NIX_PATH="/home/hm-user/.local/state/nix/defexpr/50-home-manager''${NIX_PATH:+:$NIX_PATH}"'
|
||||
assertFileContent \
|
||||
home-files/.local/state/nix/defexpr/50-home-manager/example/default.nix \
|
||||
${exampleChannel}/default.nix
|
||||
'';
|
||||
};
|
||||
}
|
||||
26
tests/modules/misc/nix/example-channels.nix
Normal file
26
tests/modules/misc/nix/example-channels.nix
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
let
|
||||
exampleChannel = pkgs.writeTextDir "default.nix" ''
|
||||
{ pkgs ? import <nixpkgs> { } }:
|
||||
|
||||
{
|
||||
example = pkgs.emptyDirectory;
|
||||
}
|
||||
'';
|
||||
in {
|
||||
config = {
|
||||
nix = {
|
||||
package = config.lib.test.mkStubPackage { };
|
||||
channels.example = exampleChannel;
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertFileContains home-path/etc/profile.d/hm-session-vars.sh \
|
||||
'export NIX_PATH="/home/hm-user/.nix-defexpr/50-home-manager''${NIX_PATH:+:$NIX_PATH}"'
|
||||
assertFileContent \
|
||||
home-files/.nix-defexpr/50-home-manager/example/default.nix \
|
||||
${exampleChannel}/default.nix
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
@ -17,6 +17,8 @@ with lib;
|
|||
'';
|
||||
};
|
||||
|
||||
nixPath = [ "/a" "/b/c" ];
|
||||
|
||||
settings = {
|
||||
use-sandbox = true;
|
||||
show-trace = true;
|
||||
|
|
@ -28,6 +30,9 @@ with lib;
|
|||
assertFileContent \
|
||||
home-files/.config/nix/nix.conf \
|
||||
${./example-settings-expected.conf}
|
||||
|
||||
assertFileContains home-path/etc/profile.d/hm-session-vars.sh \
|
||||
'export NIX_PATH="/a:/b/c''${NIX_PATH:+:$NIX_PATH}"'
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
|
|||
16
tests/modules/misc/nix/keep-old-nix-path.nix
Normal file
16
tests/modules/misc/nix/keep-old-nix-path.nix
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{ config, ... }:
|
||||
|
||||
{
|
||||
config = {
|
||||
nix = {
|
||||
package = config.lib.test.mkStubPackage { };
|
||||
nixPath = [ "/a" "/b/c" ];
|
||||
keepOldNixPath = false;
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertFileContains home-path/etc/profile.d/hm-session-vars.sh \
|
||||
'export NIX_PATH="/a:/b/c"'
|
||||
'';
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue