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.
This commit is contained in:
Matt Sturgeon 2024-10-17 19:01:34 +01:00
parent e3239b4d32
commit b9d17d5e6c
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299

View file

@ -57,29 +57,28 @@ in
}; };
}; };
config = { config =
# For now we only set this when `nixpkgs.pkgs` is defined let
# TODO: construct a default pkgs instance from pkgsPath and cfg options # TODO: construct a default pkgs instance from pkgsPath and cfg options
# https://github.com/nix-community/nixvim/issues/1784 # https://github.com/nix-community/nixvim/issues/1784
_module.args = lib.optionalAttrs opt.pkgs.isDefined {
finalPkgs =
if opt.pkgs.isDefined then
cfg.pkgs
else
# TODO: Remove once pkgs can be constructed internally
throw ''
nixvim: `nixpkgs.pkgs` is not defined. In the future, this option will be optional.
Currently a pkgs instance must be evaluated externally and assigned to `nixpkgs.pkgs` option.
'';
in
{
# We explicitly set the default override priority, so that we do not need # We explicitly set the default override priority, so that we do not need
# to evaluate finalPkgs in case an override is placed on `_module.args.pkgs`. # to evaluate finalPkgs in case an override is placed on `_module.args.pkgs`.
# After all, to determine a definition priority, we need to evaluate `._type`, # After all, to determine a definition priority, we need to evaluate `._type`,
# which is somewhat costly for Nixpkgs. With an explicit priority, we only # which is somewhat costly for Nixpkgs. With an explicit priority, we only
# evaluate the wrapper to find out that the priority is lower, and then we # evaluate the wrapper to find out that the priority is lower, and then we
# don't need to evaluate `finalPkgs`. # don't need to evaluate `finalPkgs`.
pkgs = lib.mkOverride lib.modules.defaultOverridePriority cfg.pkgs.__splicedPackages; _module.args.pkgs = lib.mkOverride lib.modules.defaultOverridePriority finalPkgs.__splicedPackages;
}; };
assertions = [
{
# TODO: Remove or rephrase once pkgs can be constructed internally
assertion = config._module.args ? pkgs;
message = ''
`nixpkgs.pkgs` is not defined. In the future, this option will be optional.
Currently a pkgs instance must be evaluated externally and assigned to `nixpkgs.pkgs` option.
'';
}
];
};
} }