mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
modules/nixpkgs: add config
option
This commit is contained in:
parent
2d68ef843a
commit
5bd04ce09a
1 changed files with 62 additions and 0 deletions
|
@ -2,11 +2,34 @@
|
|||
config,
|
||||
options,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.nixpkgs;
|
||||
opt = options.nixpkgs;
|
||||
|
||||
isConfig = x: builtins.isAttrs x || lib.isFunction x;
|
||||
|
||||
mergeConfig =
|
||||
lhs_: rhs_:
|
||||
let
|
||||
optCall = maybeFn: x: if lib.isFunction maybeFn then maybeFn x else maybeFn;
|
||||
lhs = optCall lhs_ { inherit pkgs; };
|
||||
rhs = optCall rhs_ { inherit pkgs; };
|
||||
in
|
||||
lib.recursiveUpdate lhs rhs
|
||||
// lib.optionalAttrs (lhs ? packageOverrides) {
|
||||
packageOverrides =
|
||||
pkgs:
|
||||
optCall lhs.packageOverrides pkgs // optCall (lib.attrByPath [ "packageOverrides" ] { } rhs) pkgs;
|
||||
}
|
||||
// lib.optionalAttrs (lhs ? perlPackageOverrides) {
|
||||
perlPackageOverrides =
|
||||
pkgs:
|
||||
optCall lhs.perlPackageOverrides pkgs
|
||||
// optCall (lib.attrByPath [ "perlPackageOverrides" ] { } rhs) pkgs;
|
||||
};
|
||||
in
|
||||
{
|
||||
options.nixpkgs = {
|
||||
|
@ -56,6 +79,29 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
config = lib.mkOption {
|
||||
default = { };
|
||||
example = {
|
||||
allowBroken = true;
|
||||
allowUnfree = true;
|
||||
};
|
||||
type = lib.mkOptionType {
|
||||
name = "nixpkgs-config";
|
||||
description = "nixpkgs config";
|
||||
check = x: isConfig x || lib.traceSeqN 1 x false;
|
||||
merge = loc: lib.foldr (def: mergeConfig def.value) { };
|
||||
};
|
||||
description = ''
|
||||
Global configuration for Nixpkgs.
|
||||
The complete list of [Nixpkgs configuration options] is in the [Nixpkgs manual section on global configuration].
|
||||
|
||||
Ignored when {option}`nixpkgs.pkgs` is set.
|
||||
|
||||
[Nixpkgs configuration options]: https://nixos.org/manual/nixpkgs/unstable/#sec-config-options-reference
|
||||
[Nixpkgs manual section on global configuration]: https://nixos.org/manual/nixpkgs/unstable/#chap-packageconfig
|
||||
'';
|
||||
};
|
||||
|
||||
overlays = lib.mkOption {
|
||||
type =
|
||||
let
|
||||
|
@ -170,5 +216,21 @@ in
|
|||
warnings = lib.optional (
|
||||
opt.source.isDefined && opt.source.highestPrio < (lib.mkOptionDefault null).priority
|
||||
) "Defining the option `nixpkgs.source` currently has no effect";
|
||||
|
||||
assertions = [
|
||||
{
|
||||
assertion = opt.pkgs.isDefined -> cfg.config == { };
|
||||
message = ''
|
||||
Your system configures nixpkgs with an externally created instance.
|
||||
`nixpkgs.config` options should be passed when creating the instance instead.
|
||||
|
||||
Current value:
|
||||
${lib.generators.toPretty { multiline = true; } cfg.config}
|
||||
|
||||
Defined in:
|
||||
${lib.concatMapStringsSep "\n" (file: " - ${file}") opt.config.files}
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue