1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-29 01:48:31 +02: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:
AstroSnail 2020-09-06 18:04:07 +00:00 committed by Robert Helgesson
parent 61e63c10dc
commit 1066e01707
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89

View File

@ -8,7 +8,8 @@ let
cfg = config.programs.mpv; cfg = config.programs.mpv;
mpvOption = with types; either str (either int (either bool float)); 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; mpvProfiles = with types; attrsOf mpvOptions;
mpvBindings = with types; attrsOf str; mpvBindings = with types; attrsOf str;
@ -22,18 +23,23 @@ let
string = option; string = option;
}.${typeOf option}; }.${typeOf option};
renderOptions = options: renderOptionValue = value:
concatStringsSep "\n" (mapAttrsToList (name: value: let
let rendered = renderOption value;
rendered = renderOption value; length = toString (stringLength rendered);
length = toString (stringLength rendered); in "%${length}%${rendered}";
in "${name}=%${length}%${rendered}") options);
renderProfiles = profiles: renderOptions = generators.toKeyValue {
concatStringsSep "\n" (mapAttrsToList (name: value: '' mkKeyValue =
[${name}] generators.mkKeyValueDefault { mkValueString = renderOptionValue; } "=";
${renderOptions value} listsAsDuplicateKeys = true;
'') profiles); };
renderProfiles = generators.toINI {
mkKeyValue =
generators.mkKeyValueDefault { mkValueString = renderOptionValue; } "=";
listsAsDuplicateKeys = true;
};
renderBindings = bindings: renderBindings = bindings:
concatStringsSep "\n" concatStringsSep "\n"