nixos,lib: move environment generation related copy-paste to lib
This commit is contained in:
parent
c8ea6c07c6
commit
33ae3f2fe4
3 changed files with 20 additions and 29 deletions
|
@ -6,7 +6,7 @@ with import ./attrsets.nix;
|
||||||
with import ./options.nix;
|
with import ./options.nix;
|
||||||
with import ./trivial.nix;
|
with import ./trivial.nix;
|
||||||
with import ./strings.nix;
|
with import ./strings.nix;
|
||||||
with {inherit (import ./modules.nix) mergeDefinitions; };
|
with {inherit (import ./modules.nix) mergeDefinitions filterOverrides; };
|
||||||
|
|
||||||
rec {
|
rec {
|
||||||
|
|
||||||
|
@ -166,6 +166,23 @@ rec {
|
||||||
substSubModules = m: loaOf (elemType.substSubModules m);
|
substSubModules = m: loaOf (elemType.substSubModules m);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# List or element of ...
|
||||||
|
loeOf = elemType: mkOptionType {
|
||||||
|
name = "element or list of ${elemType.name}s";
|
||||||
|
check = x: isList x || elemType.check x;
|
||||||
|
merge = loc: defs:
|
||||||
|
let
|
||||||
|
defs' = filterOverrides defs;
|
||||||
|
res = (head defs').value;
|
||||||
|
in
|
||||||
|
if isList res then concatLists (getValues defs')
|
||||||
|
else if lessThan 1 (length defs') then
|
||||||
|
throw "The option `${showOption loc}' is defined multiple times, in ${showFiles (getFiles defs)}."
|
||||||
|
else if !isString res then
|
||||||
|
throw "The option `${showOption loc}' does not have a string value, in ${showFiles (getFiles defs)}."
|
||||||
|
else res;
|
||||||
|
};
|
||||||
|
|
||||||
uniq = elemType: mkOptionType {
|
uniq = elemType: mkOptionType {
|
||||||
inherit (elemType) name check;
|
inherit (elemType) name check;
|
||||||
merge = mergeOneOption;
|
merge = mergeOneOption;
|
||||||
|
|
|
@ -41,20 +41,7 @@ in
|
||||||
strings. The latter is concatenated, interspersed with colon
|
strings. The latter is concatenated, interspersed with colon
|
||||||
characters.
|
characters.
|
||||||
'';
|
'';
|
||||||
type = types.attrsOf (mkOptionType {
|
type = types.attrsOf (types.loeOf types.str);
|
||||||
name = "a string or a list of strings";
|
|
||||||
merge = loc: defs:
|
|
||||||
let
|
|
||||||
defs' = filterOverrides defs;
|
|
||||||
res = (head defs').value;
|
|
||||||
in
|
|
||||||
if isList res then concatLists (getValues defs')
|
|
||||||
else if lessThan 1 (length defs') then
|
|
||||||
throw "The option `${showOption loc}' is defined multiple times, in ${showFiles (getFiles defs)}."
|
|
||||||
else if !isString res then
|
|
||||||
throw "The option `${showOption loc}' does not have a string value, in ${showFiles (getFiles defs)}."
|
|
||||||
else res;
|
|
||||||
});
|
|
||||||
apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v else v);
|
apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v else v);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -23,20 +23,7 @@ in
|
||||||
strings. The latter is concatenated, interspersed with colon
|
strings. The latter is concatenated, interspersed with colon
|
||||||
characters.
|
characters.
|
||||||
'';
|
'';
|
||||||
type = types.attrsOf (mkOptionType {
|
type = types.attrsOf (types.loeOf types.str);
|
||||||
name = "a string or a list of strings";
|
|
||||||
merge = loc: defs:
|
|
||||||
let
|
|
||||||
defs' = filterOverrides defs;
|
|
||||||
res = (head defs').value;
|
|
||||||
in
|
|
||||||
if isList res then concatLists (getValues defs')
|
|
||||||
else if lessThan 1 (length defs') then
|
|
||||||
throw "The option `${showOption loc}' is defined multiple times, in ${showFiles (getFiles defs)}."
|
|
||||||
else if !isString res then
|
|
||||||
throw "The option `${showOption loc}' does not have a string value, in ${showFiles (getFiles defs)}."
|
|
||||||
else res;
|
|
||||||
});
|
|
||||||
apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v else v);
|
apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v else v);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue