tests: add nixpkgs-disabled warning/assertion coverage
Evaluate `nixpkgs-disabled.nix` standalone (the harness always loads the real `nixpkgs.nix`) to verify the warning and assertion report the offending `nixpkgs.config`/`nixpkgs.overlays` definition locations.
This commit is contained in:
@@ -187,6 +187,7 @@ import nmtSrc {
|
||||
./modules/misc/news
|
||||
./modules/misc/nix
|
||||
./modules/misc/nix-remote-build
|
||||
./modules/misc/nixpkgs-disabled
|
||||
./modules/misc/specialisation
|
||||
./modules/misc/ssh-auth-sock/default.nix
|
||||
./modules/misc/xdg
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
{ lib, pkgs, ... }:
|
||||
let
|
||||
# Both options set trips the assertion; it should list both locations.
|
||||
eval = lib.evalModules {
|
||||
modules = [
|
||||
../../../../modules/misc/nixpkgs-disabled.nix
|
||||
(pkgs.path + "/nixos/modules/misc/assertions.nix")
|
||||
(pkgs.path + "/nixos/modules/misc/meta.nix")
|
||||
{ _module.args.pkgs = pkgs; }
|
||||
./offending-overlay.nix
|
||||
./offending-config.nix
|
||||
];
|
||||
};
|
||||
|
||||
files = lib.showFiles (
|
||||
lib.unique (eval.options.nixpkgs.config.files ++ eval.options.nixpkgs.overlays.files)
|
||||
);
|
||||
|
||||
failed = map (a: a.message) (lib.filter (a: !a.assertion) eval.config.assertions);
|
||||
in
|
||||
{
|
||||
nmt.script =
|
||||
let
|
||||
expected = pkgs.writeText "nixpkgs-disabled-assertion.expected" ''
|
||||
`nixpkgs` options are disabled when `home-manager.useGlobalPkgs` is enabled.
|
||||
Definitions found in ${files}.
|
||||
'';
|
||||
|
||||
actual = pkgs.writeText "nixpkgs-disabled-assertion.actual" (lib.concatStringsSep "\n--\n" failed);
|
||||
in
|
||||
''
|
||||
assertFileContent ${actual} ${expected}
|
||||
'';
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
nixpkgs-disabled-warning = ./warning.nix;
|
||||
nixpkgs-disabled-assertion = ./assertion.nix;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
nixpkgs.config.allowUnfree = true;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
nixpkgs.overlays = [ (_self: _super: { }) ];
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
{ lib, pkgs, ... }:
|
||||
let
|
||||
# nixpkgs-disabled.nix only loads under `useGlobalPkgs` (useNixpkgsModule =
|
||||
# false), which the standard harness can't toggle; evaluate it standalone.
|
||||
eval = lib.evalModules {
|
||||
modules = [
|
||||
../../../../modules/misc/nixpkgs-disabled.nix
|
||||
(pkgs.path + "/nixos/modules/misc/assertions.nix")
|
||||
(pkgs.path + "/nixos/modules/misc/meta.nix")
|
||||
{ _module.args.pkgs = pkgs; }
|
||||
./offending-overlay.nix
|
||||
];
|
||||
};
|
||||
|
||||
files = lib.showFiles eval.options.nixpkgs.overlays.files;
|
||||
in
|
||||
{
|
||||
nmt.script =
|
||||
let
|
||||
expected = pkgs.writeText "nixpkgs-disabled-warning.expected" ''
|
||||
You have set either `nixpkgs.config` or `nixpkgs.overlays` while using `home-manager.useGlobalPkgs`.
|
||||
This will soon not be possible. Please remove all `nixpkgs` options when using `home-manager.useGlobalPkgs`.
|
||||
Definitions found in ${files}.
|
||||
'';
|
||||
|
||||
actual = pkgs.writeText "nixpkgs-disabled-warning.actual" (
|
||||
lib.concatStringsSep "\n--\n" eval.config.warnings
|
||||
);
|
||||
in
|
||||
''
|
||||
assertFileContent ${actual} ${expected}
|
||||
'';
|
||||
}
|
||||
Reference in New Issue
Block a user