Skip to content

Commit 5b068e7

Browse files
committed
tests/nixpkgs: move nixpkgs module test to dedicated drv
This should be separate from `test-sources` because we want to re-use a common instance of nixpkgs throughout those tests. Also, moved the existing nixpkgs module test from `test-sources`. This partially reverts commit c4ad4d0.
1 parent 54e6dbd commit 5b068e7

File tree

3 files changed

+46
-22
lines changed

3 files changed

+46
-22
lines changed

tests/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ in
4343
no-flake = callTest ./no-flake.nix { };
4444
lib-tests = callTest ./lib-tests.nix { };
4545
maintainers = callTest ./maintainers.nix { };
46+
nixpkgs-module = callTest ./nixpkgs-module.nix { };
4647
plugins-by-name = callTest ./plugins-by-name.nix { };
4748
generated = callTest ./generated.nix { };
4849
package-options = callTest ./package-options.nix { };

tests/main.nix

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
pkgs,
99
pkgsUnfree,
1010
self,
11-
system,
1211
}:
1312
let
1413
fetchTests = callTest ./fetch-tests.nix { };
@@ -19,14 +18,12 @@ let
1918
file: name: module:
2019
mkTestDerivationFromNixvimModule {
2120
inherit name;
21+
# Use a single common instance of nixpkgs, with allowUnfree
22+
# Having a single shared instance should speed up tests a little
2223
module = {
2324
_file = file;
2425
imports = [ module ];
25-
_module.args = {
26-
# Give tests access to the flake
27-
inherit self system;
28-
inherit (self) inputs;
29-
};
26+
nixpkgs.pkgs = pkgsUnfree;
3027
};
3128
pkgs = pkgsUnfree;
3229
};

tests/test-sources/modules/nixpkgs.nix renamed to tests/nixpkgs-module.nix

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
11
{
2+
pkgs,
3+
lib,
4+
linkFarmFromDrvs,
5+
self,
6+
stdenv,
7+
}:
8+
let
9+
10+
defaultPkgs = pkgs;
11+
12+
testModule =
13+
name: module:
14+
let
15+
configuration = lib.nixvim.modules.evalNixvim {
16+
modules = lib.toList module ++ [
17+
{
18+
test = {
19+
inherit name;
20+
buildNixvim = false;
21+
runNvim = false;
22+
};
23+
}
24+
];
25+
};
26+
in
27+
configuration.config.build.test;
28+
29+
in
30+
linkFarmFromDrvs "nixpkgs-module-test" [
31+
232
# TODO: expect not setting `nixpkgs.pkgs` to throw
333

4-
overlays =
34+
(testModule "nixpkgs-overlays" (
535
{ pkgs, ... }:
636
{
7-
test.runNvim = false;
37+
nixpkgs.pkgs = defaultPkgs;
838

939
nixpkgs.overlays = [
1040
(final: prev: {
@@ -20,21 +50,15 @@
2050
'';
2151
}
2252
];
23-
};
53+
}
54+
))
2455

2556
# Test that overlays from both `nixpkgs.pkgs` _and_ `nixpkgs.overlays` are applied
26-
stacked_overlays =
27-
{
28-
inputs,
29-
system,
30-
pkgs,
31-
...
32-
}:
57+
(testModule "nixpkgs-stacked-overlay" (
58+
{ pkgs, ... }:
3359
{
34-
test.runNvim = false;
35-
36-
nixpkgs.pkgs = import inputs.nixpkgs {
37-
inherit system;
60+
nixpkgs.pkgs = import self.inputs.nixpkgs {
61+
inherit (stdenv.hostPlatform) system;
3862
overlays = [
3963
(final: prev: {
4064
foobar = "foobar";
@@ -70,5 +94,7 @@
7094
'';
7195
}
7296
];
73-
};
74-
}
97+
}
98+
))
99+
100+
]

0 commit comments

Comments
 (0)