Skip to content

Commit c168602

Browse files
committed
lib/modules: defaultPkgs -> pkgsPath
1 parent c503494 commit c168602

File tree

12 files changed

+59
-47
lines changed

12 files changed

+59
-47
lines changed

docs/default.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ let
77
# We overlay a few tweaks into pkgs, for use in the docs
88
pkgs = import ./pkgs.nix { inherit system nixpkgs; };
99
inherit (pkgs) lib;
10-
helpers = import ../lib { inherit lib; };
10+
helpers = import ../lib {
11+
inherit lib;
12+
pkgsPath = nixpkgs;
13+
};
1114

1215
nixvimPath = toString ./..;
1316

@@ -34,9 +37,6 @@ let
3437
};
3538

3639
evaledModules = helpers.modules.evalNixvim {
37-
extraSpecialArgs = {
38-
defaultPkgs = pkgs;
39-
};
4040
modules = [
4141
{ isDocs = true; }
4242
{ nixpkgs.pkgs = lib.mkDefault pkgs; }

flake-modules/legacy-packages.nix

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
modules = [
1717
{ nixpkgs.pkgs = lib.mkDefault pkgs; }
1818
];
19-
extraSpecialArgs = {
20-
defaultPkgs = pkgs;
21-
};
2219
check = false;
2320
};
2421
};

flake-modules/lib.nix

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
config,
3+
inputs,
34
lib,
45
withSystem,
56
...
@@ -13,9 +14,15 @@
1314
{ pkgs, ... }:
1415
{
1516
# NOTE: this is the publicly documented flake output we've had for a while
16-
check = import ../lib/tests.nix { inherit lib pkgs; };
17+
check = import ../lib/tests.nix {
18+
inherit lib pkgs;
19+
pkgsPath = inputs.nixpkgs;
20+
};
1721
# NOTE: user-facing so we must include the legacy `pkgs` argument
18-
helpers = import ../lib { inherit lib pkgs; };
22+
helpers = import ../lib {
23+
inherit lib pkgs;
24+
pkgsPath = inputs.nixpkgs;
25+
};
1926
}
2027
)
2128
);

lib/default.nix

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
pkgs ? null,
3+
# `pkgsPath` is required for evalNixvim's default specialArgs
4+
pkgsPath ? pkgs.path or null,
35
lib ? pkgs.lib,
46
_nixvimTests ? false,
57
...
@@ -38,24 +40,12 @@ lib.fix (
3840
extendedLib = call ./extend-lib.nix { inherit lib; };
3941
keymaps = call ./keymap-helpers.nix { };
4042
lua = call ./to-lua.nix { };
43+
modules = call ./modules.nix { inherit pkgsPath; };
4144
neovim-plugin = call ./neovim-plugin.nix { };
4245
options = call ./options.nix { };
4346
utils = call ./utils.nix { inherit _nixvimTests; };
4447
vim-plugin = call ./vim-plugin.nix { };
4548

46-
# Handle modules, which currently requires a `defaultPkgs` specialArg
47-
# FIXME: our minimal specialArgs should not need `pkgs`
48-
modules = call ./modules.nix { } // {
49-
# Minimal specialArgs required to evaluate nixvim modules
50-
specialArgs = self.modules.specialArgsWith {
51-
defaultPkgs =
52-
if pkgs == null then
53-
throw "`modules.specialArgs` cannot currently be used when nixvim's lib is built without a `pkgs` instance. This will be resolved in the future."
54-
else
55-
pkgs;
56-
};
57-
};
58-
5949
# Handle builders, which has some deprecated stuff that depends on `pkgs`
6050
builders = builders // deprecatedBuilders;
6151
inherit (self.builders)

lib/modules.nix

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
{
22
lib,
33
self,
4+
pkgsPath,
45
}:
56
rec {
7+
# Minimal specialArgs required to evaluate nixvim modules
8+
specialArgs = self.modules.specialArgsWith { };
9+
610
# Build specialArgs for evaluating nixvim modules
711
specialArgsWith =
8-
# TODO: switch defaultPkgs -> pkgsPath (i.e. pkgs.path or inputs.nixvim)
9-
# FIXME: Ideally, we should not require callers to pass in _anything_ specific
10-
{ defaultPkgs, ... }@extraSpecialArgs:
12+
extraSpecialArgs:
1113
{
12-
inherit lib defaultPkgs;
14+
inherit lib;
15+
# TODO: find a better way to handle pkgsPath 🤔
16+
# - Maybe nixvim's lib should always be provided with `pkgsPath`?
17+
# - Or maybe it can evaluate it internally, by reading `flake.lock`?
18+
pkgsPath =
19+
if pkgsPath == null then
20+
throw ''
21+
`modules.specialArgs` or `modules.evalNixvim` was used without a `pkgsPath`.
22+
You can resolve this by either specifying `pkgsPath` using `extraSpecialArgs` or `modules.specialArgsWith`,
23+
or by using a nixvim lib instance evaluated with `pkgsPath` supplied.
24+
''
25+
else
26+
builtins.toString pkgsPath;
1327
# TODO: deprecate `helpers`
1428
helpers = self;
1529
}

lib/tests.nix

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
pkgs,
3+
pkgsPath ? pkgs.path,
34
lib ? pkgs.lib,
45
...
56
}:
@@ -46,7 +47,7 @@ let
4647
let
4748
helpers = import ../lib {
4849
# NOTE: must match the user-facing functions, so we still include the `pkgs` argument
49-
inherit pkgs lib;
50+
inherit pkgs pkgsPath lib;
5051
# TODO: deprecate helpers.enableExceptInTests,
5152
# add a context option e.g. `config.isTest`?
5253
_nixvimTests = true;
@@ -65,9 +66,7 @@ let
6566
# FIXME: don't do this by default
6667
{ nixpkgs.pkgs = lib.mkDefault pkgs; }
6768
];
68-
extraSpecialArgs = {
69-
defaultPkgs = pkgs;
70-
} // extraSpecialArgs;
69+
inherit extraSpecialArgs;
7170
# Don't check assertions/warnings while evaluating nixvim config
7271
# We'll let the test derivation handle that
7372
check = false;

modules/misc/default.nix

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
{ defaultPkgs, ... }:
2-
let
3-
# We can't use config._module.args to define imports,
4-
# so we're forced to use specialArgs.defaultPkgs's path
5-
nixosModules = defaultPkgs.path + "/nixos/modules/";
6-
in
1+
{ pkgsPath, ... }:
72
{
83
imports = [
94
./context.nix
105
./nixvim-info.nix
11-
(nixosModules + "/misc/assertions.nix")
12-
(nixosModules + "/misc/meta.nix")
6+
# FIXME: this is the only reason `pkgsPath` needs to be a specialArg.
7+
# It also fails when `pkgsPath` is a string with context because meta.nix
8+
# tries to use the _file string somewhere that string-context isn't supported 😭
9+
(pkgsPath + "/nixos/modules/misc/assertions.nix")
10+
(builtins.unsafeDiscardStringContext pkgsPath + "/nixos/modules/misc/meta.nix")
1311
];
1412
}

wrappers/_shared.nix

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2+
# This flake
3+
flake,
24
# Option path where extraFiles should go
35
filesOpt ? null,
46
# Filepath prefix to apply to extraFiles
@@ -47,7 +49,12 @@ in
4749
{
4850
# Make our lib available to the host modules
4951
# NOTE: user-facing so we must include the legacy `pkgs` argument
50-
lib.nixvim = lib.mkDefault (import ../lib { inherit pkgs lib; });
52+
lib.nixvim = lib.mkDefault (
53+
import ../lib {
54+
inherit pkgs lib;
55+
pkgsPath = flake.inputs.nixpkgs;
56+
}
57+
);
5158

5259
# Make nixvim's "extended" lib available to the host's module args
5360
_module.args.nixvimLib = lib.mkDefault config.lib.nixvim.extendedLib;

wrappers/darwin.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ in
2626
type = types.submoduleWith {
2727
shorthandOnlyDefinesConfig = true;
2828
specialArgs = config.lib.nixvim.modules.specialArgsWith {
29-
defaultPkgs = pkgs;
3029
darwinConfig = config;
3130
};
3231
modules = [
@@ -39,7 +38,7 @@ in
3938
};
4039
};
4140

42-
imports = [ (import ./_shared.nix { }) ];
41+
imports = [ (import ./_shared.nix { inherit flake; }) ];
4342

4443
config = mkIf cfg.enable (mkMerge [
4544
{

wrappers/hm.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ in
2525
type = types.submoduleWith {
2626
shorthandOnlyDefinesConfig = true;
2727
specialArgs = config.lib.nixvim.modules.specialArgsWith {
28-
defaultPkgs = pkgs;
2928
hmConfig = config;
3029
};
3130
modules = [
@@ -40,6 +39,7 @@ in
4039

4140
imports = [
4241
(import ./_shared.nix {
42+
inherit flake;
4343
filesOpt = [
4444
"xdg"
4545
"configFile"

0 commit comments

Comments
 (0)