-
-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modules/nixpkgs: initial
pkgs
option, drop defaultPkgs
specialArg
This minimal implementation allows `nixpkgs.pkgs` to be defined, but does not implement evaluating an instance from a pkgsPath when _not_ defined. The `defaultPkgs` specialArg is dropped in favour of `nixpkgs.pkgs` being defined. If it's not defined, an assertion is thrown. In the future, a nixpkgs source path can be supplied, defaulting to the flake's `inputs.nixpkgs`. Along with other `nixpkgs.*` options, this will allow a `pkgs` instance to be evaluated within the module eval.
- Loading branch information
1 parent
9bec6bc
commit b1c859e
Showing
11 changed files
with
107 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,78 @@ | ||
{ defaultPkgs, lib, ... }: | ||
{ | ||
config, | ||
options, | ||
lib, | ||
... | ||
}: | ||
let | ||
# TODO: https://github.com/nix-community/nixvim/issues/1784 | ||
finalPackage = defaultPkgs; | ||
cfg = config.nixpkgs; | ||
opt = options.nixpkgs; | ||
in | ||
{ | ||
options.nixpkgs = { | ||
pkgs = lib.mkOption { | ||
# TODO: | ||
# defaultText = lib.literalExpression '' | ||
# import "''${nixos}/.." { | ||
# inherit (cfg) config overlays localSystem crossSystem; | ||
# } | ||
# ''; | ||
type = lib.types.pkgs // { | ||
description = "An evaluation of Nixpkgs; the top level attribute set of packages"; | ||
}; | ||
example = lib.literalExpression "import <nixpkgs> { }"; | ||
description = '' | ||
If set, the `pkgs` argument to all Nixvim modules is the value of this option. | ||
<!-- TODO: remove --> | ||
If unset, an assertion will trigger. In the future a `pkgs` instance will be constructed. | ||
<!-- | ||
TODO: | ||
If unset, the pkgs argument is determined as shown in the default value for this option. | ||
TODO: | ||
The default value imports the Nixpkgs input specified in Nixvim's `flake.lock`. | ||
The `config`, `overlays`, `localSystem`, and `crossSystem` come from this option's siblings. | ||
--> | ||
This option can be used by external applications to increase the performance of evaluation, | ||
or to create packages that depend on a container that should be built with the exact same | ||
evaluation of Nixpkgs, for example. | ||
Applications like this should set their default value using `lib.mkDefault`, | ||
so user-provided configuration can override it without using `lib`. | ||
E.g. Nixvim's home-manager module can re-use the `pkgs` instance from the "host" modules. | ||
> [!NOTE] | ||
> Using a distinct version of Nixpkgs with Nixvim may be an unexpected source of problems. | ||
> Use this option with care. | ||
''; | ||
}; | ||
}; | ||
|
||
config = { | ||
# 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`. | ||
# After all, to determine a definition priority, we need to evaluate `._type`, | ||
# 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 | ||
# don't need to evaluate `finalPkgs`. | ||
_module.args.pkgs = lib.mkOverride lib.modules.defaultOverridePriority finalPackage; | ||
# For now we only set this when `nixpkgs.pkgs` is defined | ||
# TODO: construct a default pkgs instance from pkgsPath and cfg options | ||
# https://github.com/nix-community/nixvim/issues/1784 | ||
_module.args = lib.optionalAttrs opt.pkgs.isDefined { | ||
# 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`. | ||
# After all, to determine a definition priority, we need to evaluate `._type`, | ||
# 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 | ||
# don't need to evaluate `finalPkgs`. | ||
pkgs = lib.mkOverride lib.modules.defaultOverridePriority cfg.pkgs.__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. | ||
''; | ||
} | ||
]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters