Merge pull request #145450 from Radvendii/master

etc module: make `.text` and `.source` the same priority

authored by Janne Heß and committed by GitHub bfd9fd29 0d67f33c

+24 -3
+1 -1
lib/default.nix
··· 119 mkFixStrictness mkOrder mkBefore mkAfter mkAliasDefinitions 120 mkAliasAndWrapDefinitions fixMergeModules mkRemovedOptionModule 121 mkRenamedOptionModule mkMergedOptionModule mkChangedOptionModule 122 - mkAliasOptionModule doRename; 123 inherit (self.options) isOption mkEnableOption mkSinkUndeclaredOptions 124 mergeDefaultOption mergeOneOption mergeEqualOption getValues 125 getFiles optionAttrSetToDocList optionAttrSetToDocList'
··· 119 mkFixStrictness mkOrder mkBefore mkAfter mkAliasDefinitions 120 mkAliasAndWrapDefinitions fixMergeModules mkRemovedOptionModule 121 mkRenamedOptionModule mkMergedOptionModule mkChangedOptionModule 122 + mkAliasOptionModule mkDerivedConfig doRename; 123 inherit (self.options) isOption mkEnableOption mkSinkUndeclaredOptions 124 mergeDefaultOption mergeOneOption mergeEqualOption getValues 125 getFiles optionAttrSetToDocList optionAttrSetToDocList'
+20
lib/modules.nix
··· 956 use = id; 957 }; 958 959 doRename = { from, to, visible, warn, use, withPriority ? true }: 960 { config, options, ... }: 961 let
··· 956 use = id; 957 }; 958 959 + /* mkDerivedConfig : Option a -> (a -> Definition b) -> Definition b 960 + 961 + Create config definitions with the same priority as the definition of another option. 962 + This should be used for option definitions where one option sets the value of another as a convenience. 963 + For instance a config file could be set with a `text` or `source` option, where text translates to a `source` 964 + value using `mkDerivedConfig options.text (pkgs.writeText "filename.conf")`. 965 + 966 + It takes care of setting the right priority using `mkOverride`. 967 + */ 968 + # TODO: make the module system error message include information about `opt` in 969 + # error messages about conflicts. E.g. introduce a variation of `mkOverride` which 970 + # adds extra location context to the definition object. This will allow context to be added 971 + # to all messages that report option locations "this value was derived from <full option name> 972 + # which was defined in <locations>". It can provide a trace of options that contributed 973 + # to definitions. 974 + mkDerivedConfig = opt: f: 975 + mkOverride 976 + (opt.highestPrio or defaultPriority) 977 + (f opt.value); 978 + 979 doRename = { from, to, visible, warn, use, withPriority ? true }: 980 { config, options, ... }: 981 let
+3 -2
nixos/modules/system/etc/etc.nix
··· 85 ''; 86 87 type = with types; attrsOf (submodule ( 88 - { name, config, ... }: 89 { options = { 90 91 enable = mkOption { ··· 172 target = mkDefault name; 173 source = mkIf (config.text != null) ( 174 let name' = "etc-" + baseNameOf name; 175 - in mkDefault (pkgs.writeText name' config.text)); 176 }; 177 178 }));
··· 85 ''; 86 87 type = with types; attrsOf (submodule ( 88 + { name, config, options, ... }: 89 { options = { 90 91 enable = mkOption { ··· 172 target = mkDefault name; 173 source = mkIf (config.text != null) ( 174 let name' = "etc-" + baseNameOf name; 175 + in mkDerivedConfig options.text (pkgs.writeText name') 176 + ); 177 }; 178 179 }));