Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions modules/top-level/test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -225,20 +241,20 @@ 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;
};
};
};

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
Expand Down
37 changes: 22 additions & 15 deletions tests/nixpkgs-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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" [
Expand Down
Loading