lib.modules: add mkDerivedConfig
mkDerivedConfig : Option a -> (a -> Definition b) -> Definition b Create config definitions with the same priority as the definition of another option. This should be used for option definitions where one option sets the value of another as a convenience. For instance a config file could be set with a `text` or `source` option, where text translates to a `source` value using `mkDerivedConfig options.text (pkgs.writeText "filename.conf")`. It takes care of setting the right priority using `mkOverride`.
This commit is contained in:
parent
0e590c91d2
commit
0bef0c38f7
|
@ -119,7 +119,7 @@ let
|
||||||
mkFixStrictness mkOrder mkBefore mkAfter mkAliasDefinitions
|
mkFixStrictness mkOrder mkBefore mkAfter mkAliasDefinitions
|
||||||
mkAliasAndWrapDefinitions fixMergeModules mkRemovedOptionModule
|
mkAliasAndWrapDefinitions fixMergeModules mkRemovedOptionModule
|
||||||
mkRenamedOptionModule mkMergedOptionModule mkChangedOptionModule
|
mkRenamedOptionModule mkMergedOptionModule mkChangedOptionModule
|
||||||
mkAliasOptionModule doRename;
|
mkAliasOptionModule mkDerivedConfig doRename;
|
||||||
inherit (self.options) isOption mkEnableOption mkSinkUndeclaredOptions
|
inherit (self.options) isOption mkEnableOption mkSinkUndeclaredOptions
|
||||||
mergeDefaultOption mergeOneOption mergeEqualOption getValues
|
mergeDefaultOption mergeOneOption mergeEqualOption getValues
|
||||||
getFiles optionAttrSetToDocList optionAttrSetToDocList'
|
getFiles optionAttrSetToDocList optionAttrSetToDocList'
|
||||||
|
|
|
@ -956,6 +956,26 @@ rec {
|
||||||
use = id;
|
use = id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* mkDerivedConfig : Option a -> (a -> Definition b) -> Definition b
|
||||||
|
|
||||||
|
Create config definitions with the same priority as the definition of another option.
|
||||||
|
This should be used for option definitions where one option sets the value of another as a convenience.
|
||||||
|
For instance a config file could be set with a `text` or `source` option, where text translates to a `source`
|
||||||
|
value using `mkDerivedConfig options.text (pkgs.writeText "filename.conf")`.
|
||||||
|
|
||||||
|
It takes care of setting the right priority using `mkOverride`.
|
||||||
|
*/
|
||||||
|
# TODO: make the module system error message include information about `opt` in
|
||||||
|
# error messages about conflicts. E.g. introduce a variation of `mkOverride` which
|
||||||
|
# adds extra location context to the definition object. This will allow context to be added
|
||||||
|
# to all messages that report option locations "this value was derived from <full option name>
|
||||||
|
# which was defined in <locations>". It can provide a trace of options that contributed
|
||||||
|
# to definitions.
|
||||||
|
mkDerivedConfig = opt: f:
|
||||||
|
mkOverride
|
||||||
|
(opt.highestPrio or defaultPriority)
|
||||||
|
(f opt.value);
|
||||||
|
|
||||||
doRename = { from, to, visible, warn, use, withPriority ? true }:
|
doRename = { from, to, visible, warn, use, withPriority ? true }:
|
||||||
{ config, options, ... }:
|
{ config, options, ... }:
|
||||||
let
|
let
|
||||||
|
|
|
@ -172,9 +172,8 @@ in
|
||||||
target = mkDefault name;
|
target = mkDefault name;
|
||||||
source = mkIf (config.text != null) (
|
source = mkIf (config.text != null) (
|
||||||
let name' = "etc-" + baseNameOf name;
|
let name' = "etc-" + baseNameOf name;
|
||||||
in mkOverride
|
in mkDerivedConfig options.text (pkgs.writeText name')
|
||||||
(options.text.highestPrio or lib.modules.defaultPriority)
|
);
|
||||||
(pkgs.writeText name' config.text));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user