Skip to content

Commit 3a595aa

Browse files
committed
modules/nixpkgs: add overlays option
Based on the `nixpkgs.overlays` option available in NixOS, allows users to further customize the `pkgs` instance used when evaluating nixvim. The standard module tests are now provided a few extra module args to enable a test where we instantiate a custom nixpkgs instance.
1 parent f086ad5 commit 3a595aa

File tree

3 files changed

+123
-1
lines changed

3 files changed

+123
-1
lines changed

modules/top-level/nixpkgs.nix

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,47 @@ in
5555
> Use this option with care.
5656
'';
5757
};
58+
59+
overlays = lib.mkOption {
60+
type =
61+
let
62+
overlayType = lib.mkOptionType {
63+
name = "nixpkgs-overlay";
64+
description = "nixpkgs overlay";
65+
check = lib.isFunction;
66+
merge = lib.mergeOneOption;
67+
};
68+
in
69+
lib.types.listOf overlayType;
70+
default = [ ];
71+
# FIXME: use an example that is topical for vim
72+
example = lib.literalExpression ''
73+
[
74+
(self: super: {
75+
openssh = super.openssh.override {
76+
hpnSupport = true;
77+
kerberos = self.libkrb5;
78+
};
79+
})
80+
]
81+
'';
82+
description = ''
83+
List of overlays to apply to Nixpkgs.
84+
This option allows modifying the Nixpkgs package set accessed through the `pkgs` module argument.
85+
86+
For details, see the [Overlays chapter in the Nixpkgs manual](https://nixos.org/manual/nixpkgs/stable/#chap-overlays).
87+
88+
<!-- TODO: Remove -->
89+
Overlays specified using the {option}`nixpkgs.overlays` option will be
90+
applied after the overlays that were already included in `nixpkgs.pkgs`.
91+
92+
<!--
93+
TODO:
94+
If the {option}`nixpkgs.pkgs` option is set, overlays specified using `nixpkgs.overlays`
95+
will be applied after the overlays that were already included in `nixpkgs.pkgs`.
96+
-->
97+
'';
98+
};
5899
};
59100

60101
config =
@@ -64,7 +105,7 @@ in
64105

65106
finalPkgs =
66107
if opt.pkgs.isDefined then
67-
cfg.pkgs
108+
cfg.pkgs.appendOverlays cfg.overlays
68109
else
69110
# TODO: Remove once pkgs can be constructed internally
70111
throw ''

tests/default.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2+
self, # This flake
3+
system,
24
lib ? pkgs.lib,
35
helpers,
46
pkgs,
@@ -16,6 +18,11 @@ let
1618
module = {
1719
_file = file;
1820
imports = [ module ];
21+
_module.args = {
22+
# Give tests access to the flake
23+
inherit self system;
24+
inherit (self) inputs;
25+
};
1926
};
2027
pkgs = pkgsUnfree;
2128
};
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
# TODO: expect not setting `nixpkgs.pkgs` to throw
3+
4+
overlays =
5+
{ pkgs, ... }:
6+
{
7+
test.runNvim = false;
8+
9+
nixpkgs.overlays = [
10+
(final: prev: {
11+
foobar = "foobar";
12+
})
13+
];
14+
15+
assertions = [
16+
{
17+
assertion = pkgs.foobar or null == "foobar";
18+
message = ''
19+
Expected `pkgs.foobar` to be "foobar"
20+
'';
21+
}
22+
];
23+
};
24+
25+
# Test that overlays from both `nixpkgs.pkgs` _and_ `nixpkgs.overlays` are applied
26+
stacked_overlays =
27+
{
28+
inputs,
29+
system,
30+
pkgs,
31+
...
32+
}:
33+
{
34+
test.runNvim = false;
35+
36+
nixpkgs.pkgs = import inputs.nixpkgs {
37+
inherit system;
38+
overlays = [
39+
(final: prev: {
40+
foobar = "foobar";
41+
conflict = "a";
42+
})
43+
];
44+
};
45+
46+
nixpkgs.overlays = [
47+
(final: prev: {
48+
hello = "world";
49+
conflict = "b";
50+
})
51+
];
52+
53+
assertions = [
54+
{
55+
assertion = pkgs.foobar or null == "foobar";
56+
message = ''
57+
Expected `pkgs.foobar` to be "foobar"
58+
'';
59+
}
60+
{
61+
assertion = pkgs.hello or null == "world";
62+
message = ''
63+
Expected `pkgs.hello` to be "world"
64+
'';
65+
}
66+
{
67+
assertion = pkgs.conflict or null == "b";
68+
message = ''
69+
Expected `pkgs.conflict` to be "b"
70+
'';
71+
}
72+
];
73+
};
74+
}

0 commit comments

Comments
 (0)