mirror of
https://github.com/RGBCube/hjem
synced 2025-10-14 13:42:22 +00:00
modules/common/user: ensure generator generates str or drv
This commit is contained in:
parent
4c6022398a
commit
85a1964abf
1 changed files with 13 additions and 4 deletions
|
@ -13,7 +13,7 @@
|
||||||
inherit (lib.modules) mkIf mkDefault mkDerivedConfig mkMerge;
|
inherit (lib.modules) mkIf mkDefault mkDerivedConfig mkMerge;
|
||||||
inherit (lib.options) mkOption literalExpression mkEnableOption;
|
inherit (lib.options) mkOption literalExpression mkEnableOption;
|
||||||
inherit (lib.strings) hasPrefix;
|
inherit (lib.strings) hasPrefix;
|
||||||
inherit (lib.types) anything attrsOf bool either functionTo lines listOf nullOr package path str submodule oneOf int;
|
inherit (lib.types) addCheck anything attrsOf bool either functionTo int lines listOf nullOr package path str submodule oneOf;
|
||||||
inherit (builtins) isList;
|
inherit (builtins) isList;
|
||||||
|
|
||||||
cfg = config;
|
cfg = config;
|
||||||
|
@ -59,7 +59,13 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
generator = lib.mkOption {
|
generator = lib.mkOption {
|
||||||
type = nullOr (functionTo (either options.source.type options.text.type));
|
# functionTo doesn't actually check the return type, so do that ourselves
|
||||||
|
type = addCheck (nullOr (functionTo (either options.source.type options.text.type))) (x: let
|
||||||
|
generatedValue = x config.value;
|
||||||
|
generatesDrv = options.source.type.check generatedValue;
|
||||||
|
generatesStr = options.text.type.check generatedValue;
|
||||||
|
in
|
||||||
|
x != null -> (generatesDrv || generatesStr));
|
||||||
default = null;
|
default = null;
|
||||||
description = ''
|
description = ''
|
||||||
Function that when applied to `value` will create the `source` or `text` of the file.
|
Function that when applied to `value` will create the `source` or `text` of the file.
|
||||||
|
@ -112,6 +118,9 @@
|
||||||
|
|
||||||
config = let
|
config = let
|
||||||
generatedValue = config.generator config.value;
|
generatedValue = config.generator config.value;
|
||||||
|
hasGenerator = config.generator != null;
|
||||||
|
generatesDrv = options.source.type.check generatedValue;
|
||||||
|
generatesStr = options.text.type.check generatedValue;
|
||||||
in
|
in
|
||||||
mkMerge [
|
mkMerge [
|
||||||
{
|
{
|
||||||
|
@ -123,11 +132,11 @@
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
(lib.mkIf (config.generator != null && options.source.type.check generatedValue) {
|
(lib.mkIf (hasGenerator && generatesDrv) {
|
||||||
source = mkDefault generatedValue;
|
source = mkDefault generatedValue;
|
||||||
})
|
})
|
||||||
|
|
||||||
(lib.mkIf (config.generator != null && options.text.type.check generatedValue) {
|
(lib.mkIf (hasGenerator && generatesStr) {
|
||||||
text = mkDefault generatedValue;
|
text = mkDefault generatedValue;
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue