diff --git a/tests/default.nix b/tests/default.nix index a5a0c3127..4856e9e54 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -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 diff --git a/tests/modules/misc/nixpkgs-disabled/assertion.nix b/tests/modules/misc/nixpkgs-disabled/assertion.nix new file mode 100644 index 000000000..07052135d --- /dev/null +++ b/tests/modules/misc/nixpkgs-disabled/assertion.nix @@ -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} + ''; +} diff --git a/tests/modules/misc/nixpkgs-disabled/default.nix b/tests/modules/misc/nixpkgs-disabled/default.nix new file mode 100644 index 000000000..8b8f39e0f --- /dev/null +++ b/tests/modules/misc/nixpkgs-disabled/default.nix @@ -0,0 +1,4 @@ +{ + nixpkgs-disabled-warning = ./warning.nix; + nixpkgs-disabled-assertion = ./assertion.nix; +} diff --git a/tests/modules/misc/nixpkgs-disabled/offending-config.nix b/tests/modules/misc/nixpkgs-disabled/offending-config.nix new file mode 100644 index 000000000..e95ec3c05 --- /dev/null +++ b/tests/modules/misc/nixpkgs-disabled/offending-config.nix @@ -0,0 +1,3 @@ +{ + nixpkgs.config.allowUnfree = true; +} diff --git a/tests/modules/misc/nixpkgs-disabled/offending-overlay.nix b/tests/modules/misc/nixpkgs-disabled/offending-overlay.nix new file mode 100644 index 000000000..b6c8b6e3f --- /dev/null +++ b/tests/modules/misc/nixpkgs-disabled/offending-overlay.nix @@ -0,0 +1,3 @@ +{ + nixpkgs.overlays = [ (_self: _super: { }) ]; +} diff --git a/tests/modules/misc/nixpkgs-disabled/warning.nix b/tests/modules/misc/nixpkgs-disabled/warning.nix new file mode 100644 index 000000000..deec16066 --- /dev/null +++ b/tests/modules/misc/nixpkgs-disabled/warning.nix @@ -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} + ''; +}