1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-05 10:49:44 +01:00
home-manager/modules/programs/mpv.nix

144 lines
3.7 KiB
Nix
Raw Normal View History

2019-04-30 03:25:53 +02:00
{ 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:
2020-02-02 00:39:17 +01:00
concatStringsSep "\n" (mapAttrsToList (name: value:
let
rendered = renderOption value;
length = toString (stringLength rendered);
in "${name}=%${length}%${rendered}") options);
2019-04-30 03:25:53 +02:00
renderProfiles = profiles:
2020-02-02 00:39:17 +01:00
concatStringsSep "\n" (mapAttrsToList (name: value: ''
[${name}]
${renderOptions value}
'') profiles);
2019-04-30 03:25:53 +02:00
renderBindings = bindings:
concatStringsSep "\n"
2020-02-02 00:39:17 +01:00
(mapAttrsToList (name: value: "${name} ${value}") bindings);
2019-04-30 03:25:53 +02:00
in {
options = {
programs.mpv = {
enable = mkEnableOption "mpv";
2019-09-02 17:52:02 +02:00
scripts = mkOption {
type = with types; listOf (either package str);
2020-02-02 00:39:17 +01:00
default = [ ];
2019-09-02 17:52:02 +02:00
example = literalExample "[ pkgs.mpvScripts.mpris ]";
description = ''
List of scripts to use with mpv.
'';
};
2019-04-30 03:25:53 +02:00
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;
2020-02-02 00:39:17 +01:00
default = { };
2019-04-30 03:25:53 +02:00
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;
2020-02-02 00:39:17 +01:00
default = { };
2019-04-30 03:25:53 +02:00
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;
2020-02-02 00:39:17 +01:00
default = { };
2019-04-30 03:25:53 +02:00
example = literalExample ''
{
WHEEL_UP = "seek 10";
WHEEL_DOWN = "seek -10";
"Alt+0" = "set window-scale 0.5";
}
'';
};
};
};
config = mkIf cfg.enable (mkMerge [
{
2020-02-02 00:39:17 +01:00
home.packages = [
(if cfg.scripts == [ ] then
pkgs.mpv
else
pkgs.wrapMpv pkgs.mpv-unwrapped { scripts = cfg.scripts; })
2020-02-02 00:39:17 +01:00
];
2019-04-30 03:25:53 +02:00
}
2020-02-02 00:39:17 +01:00
(mkIf (cfg.config != { } || cfg.profiles != { }) {
2019-04-30 03:25:53 +02:00
xdg.configFile."mpv/mpv.conf".text = ''
2020-02-02 00:39:17 +01:00
${optionalString (cfg.config != { }) (renderOptions cfg.config)}
${optionalString (cfg.profiles != { }) (renderProfiles cfg.profiles)}
2019-04-30 03:25:53 +02:00
'';
})
2020-02-02 00:39:17 +01:00
(mkIf (cfg.bindings != { }) {
2019-04-30 03:25:53 +02:00
xdg.configFile."mpv/input.conf".text = renderBindings cfg.bindings;
})
]);
meta.maintainers = with maintainers; [ tadeokondrak ];
}