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 c4ad4d0b2e.
This commit is contained in:
Matt Sturgeon 2025-01-15 17:24:23 +00:00
parent 54e6dbd8c8
commit 5b068e7f8f
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
3 changed files with 46 additions and 22 deletions

View file

@ -43,6 +43,7 @@ in
no-flake = callTest ./no-flake.nix { }; no-flake = callTest ./no-flake.nix { };
lib-tests = callTest ./lib-tests.nix { }; lib-tests = callTest ./lib-tests.nix { };
maintainers = callTest ./maintainers.nix { }; maintainers = callTest ./maintainers.nix { };
nixpkgs-module = callTest ./nixpkgs-module.nix { };
plugins-by-name = callTest ./plugins-by-name.nix { }; plugins-by-name = callTest ./plugins-by-name.nix { };
generated = callTest ./generated.nix { }; generated = callTest ./generated.nix { };
package-options = callTest ./package-options.nix { }; package-options = callTest ./package-options.nix { };

View file

@ -8,7 +8,6 @@
pkgs, pkgs,
pkgsUnfree, pkgsUnfree,
self, self,
system,
}: }:
let let
fetchTests = callTest ./fetch-tests.nix { }; fetchTests = callTest ./fetch-tests.nix { };
@ -19,14 +18,12 @@ let
file: name: module: file: name: module:
mkTestDerivationFromNixvimModule { mkTestDerivationFromNixvimModule {
inherit name; inherit name;
# Use a single common instance of nixpkgs, with allowUnfree
# Having a single shared instance should speed up tests a little
module = { module = {
_file = file; _file = file;
imports = [ module ]; imports = [ module ];
_module.args = { nixpkgs.pkgs = pkgsUnfree;
# Give tests access to the flake
inherit self system;
inherit (self) inputs;
};
}; };
pkgs = pkgsUnfree; pkgs = pkgsUnfree;
}; };

View file

@ -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 # TODO: expect not setting `nixpkgs.pkgs` to throw
overlays = (testModule "nixpkgs-overlays" (
{ pkgs, ... }: { pkgs, ... }:
{ {
test.runNvim = false; nixpkgs.pkgs = defaultPkgs;
nixpkgs.overlays = [ nixpkgs.overlays = [
(final: prev: { (final: prev: {
@ -20,21 +50,15 @@
''; '';
} }
]; ];
}; }
))
# Test that overlays from both `nixpkgs.pkgs` _and_ `nixpkgs.overlays` are applied # Test that overlays from both `nixpkgs.pkgs` _and_ `nixpkgs.overlays` are applied
stacked_overlays = (testModule "nixpkgs-stacked-overlay" (
{ pkgs, ... }:
{ {
inputs, nixpkgs.pkgs = import self.inputs.nixpkgs {
system, inherit (stdenv.hostPlatform) system;
pkgs,
...
}:
{
test.runNvim = false;
nixpkgs.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ overlays = [
(final: prev: { (final: prev: {
foobar = "foobar"; foobar = "foobar";
@ -70,5 +94,7 @@
''; '';
} }
]; ];
};
} }
))
]