mirror of
https://github.com/nix-community/home-manager
synced 2024-10-31 16:29:44 +01:00
mpv: use lib.generators to render config
There exist mpv configurations which cannot be expressed in `programs.mpv.config` currently. For example, it is impossible to use multiple 'profile' attributes. This commit changes the way config and profiles are parsed, using `lib.generators.toKeyValue` and `lib.generators.toINI`, to allow for these kinds of configurations through the use of `listsAsDuplicateKeys`.
This commit is contained in:
parent
61e63c10dc
commit
1066e01707
1 changed files with 18 additions and 12 deletions
|
@ -8,7 +8,8 @@ let
|
|||
cfg = config.programs.mpv;
|
||||
|
||||
mpvOption = with types; either str (either int (either bool float));
|
||||
mpvOptions = with types; attrsOf mpvOption;
|
||||
mpvOptionDup = with types; either mpvOption (listOf mpvOption);
|
||||
mpvOptions = with types; attrsOf mpvOptionDup;
|
||||
mpvProfiles = with types; attrsOf mpvOptions;
|
||||
mpvBindings = with types; attrsOf str;
|
||||
|
||||
|
@ -22,18 +23,23 @@ let
|
|||
string = option;
|
||||
}.${typeOf option};
|
||||
|
||||
renderOptions = options:
|
||||
concatStringsSep "\n" (mapAttrsToList (name: value:
|
||||
let
|
||||
rendered = renderOption value;
|
||||
length = toString (stringLength rendered);
|
||||
in "${name}=%${length}%${rendered}") options);
|
||||
renderOptionValue = value:
|
||||
let
|
||||
rendered = renderOption value;
|
||||
length = toString (stringLength rendered);
|
||||
in "%${length}%${rendered}";
|
||||
|
||||
renderProfiles = profiles:
|
||||
concatStringsSep "\n" (mapAttrsToList (name: value: ''
|
||||
[${name}]
|
||||
${renderOptions value}
|
||||
'') profiles);
|
||||
renderOptions = generators.toKeyValue {
|
||||
mkKeyValue =
|
||||
generators.mkKeyValueDefault { mkValueString = renderOptionValue; } "=";
|
||||
listsAsDuplicateKeys = true;
|
||||
};
|
||||
|
||||
renderProfiles = generators.toINI {
|
||||
mkKeyValue =
|
||||
generators.mkKeyValueDefault { mkValueString = renderOptionValue; } "=";
|
||||
listsAsDuplicateKeys = true;
|
||||
};
|
||||
|
||||
renderBindings = bindings:
|
||||
concatStringsSep "\n"
|
||||
|
|
Loading…
Reference in a new issue