Skip to content

Commit 04f33f0

Browse files
committed
modules/nixpkgs: restructure nixpkgs.pkgs.isDefined assertion
We can throw inline to ensure our error is displayed before any attempt to use the (non-existent) `pkgs` arg results in a less helpful error.
1 parent 036e116 commit 04f33f0

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

modules/top-level/nixpkgs.nix

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,28 @@ in
5757
};
5858
};
5959

60-
config = {
61-
# For now we only set this when `nixpkgs.pkgs` is defined
62-
# TODO: construct a default pkgs instance from pkgsPath and cfg options
63-
# https://github.com/nix-community/nixvim/issues/1784
64-
_module.args = lib.optionalAttrs opt.pkgs.isDefined {
60+
config =
61+
let
62+
# TODO: construct a default pkgs instance from pkgsPath and cfg options
63+
# https://github.com/nix-community/nixvim/issues/1784
64+
65+
finalPkgs =
66+
if opt.pkgs.isDefined then
67+
cfg.pkgs
68+
else
69+
# TODO: Remove once pkgs can be constructed internally
70+
throw ''
71+
nixvim: `nixpkgs.pkgs` is not defined. In the future, this option will be optional.
72+
Currently a pkgs instance must be evaluated externally and assigned to `nixpkgs.pkgs` option.
73+
'';
74+
in
75+
{
6576
# We explicitly set the default override priority, so that we do not need
6677
# to evaluate finalPkgs in case an override is placed on `_module.args.pkgs`.
6778
# After all, to determine a definition priority, we need to evaluate `._type`,
6879
# which is somewhat costly for Nixpkgs. With an explicit priority, we only
6980
# evaluate the wrapper to find out that the priority is lower, and then we
7081
# don't need to evaluate `finalPkgs`.
71-
pkgs = lib.mkOverride lib.modules.defaultOverridePriority cfg.pkgs.__splicedPackages;
82+
_module.args.pkgs = lib.mkOverride lib.modules.defaultOverridePriority finalPkgs.__splicedPackages;
7283
};
73-
74-
assertions = [
75-
{
76-
# TODO: Remove or rephrase once pkgs can be constructed internally
77-
assertion = config._module.args ? pkgs;
78-
message = ''
79-
`nixpkgs.pkgs` is not defined. In the future, this option will be optional.
80-
Currently a pkgs instance must be evaluated externally and assigned to `nixpkgs.pkgs` option.
81-
'';
82-
}
83-
];
84-
};
8584
}

0 commit comments

Comments
 (0)