Skip to content

Commit

Permalink
tests/nixpkgs: move nixpkgs module test to dedicated drv
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MattSturgeon committed Jan 15, 2025
1 parent 54e6dbd commit 5b068e7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 22 deletions.
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ in
no-flake = callTest ./no-flake.nix { };
lib-tests = callTest ./lib-tests.nix { };
maintainers = callTest ./maintainers.nix { };
nixpkgs-module = callTest ./nixpkgs-module.nix { };
plugins-by-name = callTest ./plugins-by-name.nix { };
generated = callTest ./generated.nix { };
package-options = callTest ./package-options.nix { };
Expand Down
9 changes: 3 additions & 6 deletions tests/main.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
pkgs,
pkgsUnfree,
self,
system,
}:
let
fetchTests = callTest ./fetch-tests.nix { };
Expand All @@ -19,14 +18,12 @@ let
file: name: module:
mkTestDerivationFromNixvimModule {
inherit name;
# Use a single common instance of nixpkgs, with allowUnfree
# Having a single shared instance should speed up tests a little
module = {
_file = file;
imports = [ module ];
_module.args = {
# Give tests access to the flake
inherit self system;
inherit (self) inputs;
};
nixpkgs.pkgs = pkgsUnfree;
};
pkgs = pkgsUnfree;
};
Expand Down
58 changes: 42 additions & 16 deletions tests/test-sources/modules/nixpkgs.nix → tests/nixpkgs-module.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
{
pkgs,
lib,
linkFarmFromDrvs,
self,
stdenv,
}:
let

defaultPkgs = pkgs;

testModule =
name: module:
let
configuration = lib.nixvim.modules.evalNixvim {
modules = lib.toList module ++ [
{
test = {
inherit name;
buildNixvim = false;
runNvim = false;
};
}
];
};
in
configuration.config.build.test;

in
linkFarmFromDrvs "nixpkgs-module-test" [

# TODO: expect not setting `nixpkgs.pkgs` to throw

overlays =
(testModule "nixpkgs-overlays" (
{ pkgs, ... }:
{
test.runNvim = false;
nixpkgs.pkgs = defaultPkgs;

nixpkgs.overlays = [
(final: prev: {
Expand All @@ -20,21 +50,15 @@
'';
}
];
};
}
))

# Test that overlays from both `nixpkgs.pkgs` _and_ `nixpkgs.overlays` are applied
stacked_overlays =
{
inputs,
system,
pkgs,
...
}:
(testModule "nixpkgs-stacked-overlay" (
{ pkgs, ... }:
{
test.runNvim = false;

nixpkgs.pkgs = import inputs.nixpkgs {
inherit system;
nixpkgs.pkgs = import self.inputs.nixpkgs {
inherit (stdenv.hostPlatform) system;
overlays = [
(final: prev: {
foobar = "foobar";
Expand Down Expand Up @@ -70,5 +94,7 @@
'';
}
];
};
}
}
))

]

0 comments on commit 5b068e7

Please sign in to comment.