diff options
author | Katharina Fey <kookie@spacekookie.de> | 2019-10-05 12:06:29 +0000 |
---|---|---|
committer | Katharina Fey <kookie@spacekookie.de> | 2019-10-05 12:42:50 +0000 |
commit | 1148b1d122bc03e9a3665856c9b7bb96bd4e3994 (patch) | |
tree | 1a9586de593790e236349d5caa0abdff7f3f6856 /home-manager/modules/programs/mpv.nix | |
parent | 919d4e75699aa4ba456fd2d3d416a0522c9c7294 (diff) | |
parent | 8bddc1adab0f7a51476f819fa2197353e8e1d136 (diff) |
Add 'home-manager/' from commit '8bddc1adab0f7a51476f819fa2197353e8e1d136'
git-subtree-dir: home-manager
git-subtree-mainline: 919d4e75699aa4ba456fd2d3d416a0522c9c7294
git-subtree-split: 8bddc1adab0f7a51476f819fa2197353e8e1d136
Diffstat (limited to 'home-manager/modules/programs/mpv.nix')
-rw-r--r-- | home-manager/modules/programs/mpv.nix | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/home-manager/modules/programs/mpv.nix b/home-manager/modules/programs/mpv.nix new file mode 100644 index 00000000000..1051f71ccd6 --- /dev/null +++ b/home-manager/modules/programs/mpv.nix @@ -0,0 +1,152 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + inherit (builtins) typeOf stringLength; + + cfg = config.programs.mpv; + + mpvOption = with types; either str (either int (either bool float)); + mpvOptions = with types; attrsOf mpvOption; + mpvProfiles = with types; attrsOf mpvOptions; + mpvBindings = with types; attrsOf str; + + renderOption = option: + rec { + int = toString option; + float = int; + + bool = if option then "yes" else "no"; + + string = option; + }.${typeOf option}; + + renderOptions = options: + concatStringsSep "\n" + (mapAttrsToList + (name: value: + let + rendered = renderOption value; + length = toString (stringLength rendered); + in + "${name}=%${length}%${rendered}") + options); + + renderProfiles = profiles: + concatStringsSep "\n" + (mapAttrsToList + (name: value: '' + [${name}] + ${renderOptions value} + '') + profiles); + + renderBindings = bindings: + concatStringsSep "\n" + (mapAttrsToList + (name: value: + "${name} ${value}") + bindings); + +in { + options = { + programs.mpv = { + enable = mkEnableOption "mpv"; + + scripts = mkOption { + type = types.listOf types.package; + default = []; + example = literalExample "[ pkgs.mpvScripts.mpris ]"; + description = '' + List of scripts to use with mpv. + ''; + }; + + config = mkOption { + description = '' + Configuration written to + <filename>~/.config/mpv/mpv.conf</filename>. See + <citerefentry> + <refentrytitle>mpv</refentrytitle> + <manvolnum>1</manvolnum> + </citerefentry> + for the full list of options. + ''; + type = mpvOptions; + default = {}; + example = literalExample '' + { + profile = "gpu-hq"; + force-window = "yes"; + ytdl-format = "bestvideo+bestaudio"; + cache-default = 4000000; + } + ''; + }; + + profiles = mkOption { + description = '' + Sub-configuration options for specific profiles written to + <filename>~/.config/mpv/mpv.conf</filename>. See + <option>programs.mpv.config</option> for more information. + ''; + type = mpvProfiles; + default = {}; + example = literalExample '' + { + fast = { + vo = "vdpau"; + }; + "protocol.dvd" = { + profile-desc = "profile for dvd:// streams"; + alang = "en"; + }; + } + ''; + }; + + bindings = mkOption { + description = '' + Input configuration written to + <filename>~/.config/mpv/input.conf</filename>. See + <citerefentry> + <refentrytitle>mpv</refentrytitle> + <manvolnum>1</manvolnum> + </citerefentry> + for the full list of options. + ''; + type = mpvBindings; + default = {}; + example = literalExample '' + { + WHEEL_UP = "seek 10"; + WHEEL_DOWN = "seek -10"; + "Alt+0" = "set window-scale 0.5"; + } + ''; + }; + }; + }; + + config = mkIf cfg.enable (mkMerge [ + { + home.packages = [( + if cfg.scripts == [] + then pkgs.mpv + else pkgs.mpv-with-scripts.override { scripts = cfg.scripts; } + )]; + } + (mkIf (cfg.config != {} || cfg.profiles != {}) { + xdg.configFile."mpv/mpv.conf".text = '' + ${optionalString (cfg.config != {}) (renderOptions cfg.config)} + ${optionalString (cfg.profiles != {}) (renderProfiles cfg.profiles)} + ''; + }) + (mkIf (cfg.bindings != {}) { + xdg.configFile."mpv/input.conf".text = renderBindings cfg.bindings; + }) + ]); + + meta.maintainers = with maintainers; [ tadeokondrak ]; +} |