diff --git a/modules/top-level/test.nix b/modules/top-level/test.nix index 79a3229c7e..95dc945ca9 100644 --- a/modules/top-level/test.nix +++ b/modules/top-level/test.nix @@ -169,6 +169,22 @@ in ''; internal = true; }; + + # Primarily intended for internal use, allowing us to test `pkgs` while using a `runCommand` from a different nixpkgs instance. + runCommand = lib.mkOption { + type = + with lib.types; + addCheck unspecified builtins.isFunction + // { + description = "runCommand function"; + }; + description = '' + `runCommand` function used to construct `build.test`. + ''; + defaultText = lib.literalExpression "pkgs.runCommandLocal"; + default = pkgs.runCommandLocal; + internal = true; + }; }; options.build = { @@ -225,12 +241,12 @@ in }; any = { predicate = v: builtins.any (lib.hasInfix v); - message = v: "Expected ${lib.toJSON v} infix to be present."; + message = v: "Expected ${builtins.toJSON v} infix to be present."; valueType = lib.types.str; }; anyExact = { predicate = builtins.elem; - message = v: "Expected ${lib.toJSON v} to be present."; + message = v: "Expected ${builtins.toJSON v} to be present."; valueType = lib.types.str; }; }; @@ -238,7 +254,7 @@ in build.test = assert lib.assertMsg (cfg.runNvim -> cfg.buildNixvim) "`test.runNvim` requires `test.buildNixvim`."; - pkgs.runCommandLocal cfg.name + cfg.runCommand cfg.name { nativeBuildInputs = lib.optionals cfg.buildNixvim [ config.build.packageUnchecked diff --git a/tests/nixpkgs-module.nix b/tests/nixpkgs-module.nix index 20e3bed1a3..ba04381b8a 100644 --- a/tests/nixpkgs-module.nix +++ b/tests/nixpkgs-module.nix @@ -4,27 +4,34 @@ linkFarmFromDrvs, self, stdenv, + runCommandLocal, }: let defaultPkgs = pkgs; - testModule = + # Only imports the bare minimum modules, to ensure we are not accidentally evaluating `pkgs.*` + evalModule = name: module: - let - configuration = lib.nixvim.modules.evalNixvim { - modules = lib.toList module ++ [ - { - test = { - inherit name; - buildNixvim = false; - runNvim = false; - }; - } - ]; - }; - in - configuration.config.build.test; + lib.evalModules { + modules = lib.toList module ++ [ + { + _module.check = false; + flake = self; + test = { + inherit name; + buildNixvim = false; + runNvim = false; + runCommand = runCommandLocal; + }; + } + ../modules/misc + ../modules/top-level/test.nix + ../modules/top-level/nixpkgs.nix + ]; + }; + + testModule = name: module: (evalModule name module).config.build.test; in linkFarmFromDrvs "nixpkgs-module-test" [