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));
|
2020-09-06 20:04:07 +02:00
|
|
|
mpvOptionDup = with types; either mpvOption (listOf mpvOption);
|
|
|
|
mpvOptions = with types; attrsOf mpvOptionDup;
|
2019-04-30 03:25:53 +02:00
|
|
|
mpvProfiles = with types; attrsOf mpvOptions;
|
|
|
|
mpvBindings = with types; attrsOf str;
|
2021-01-11 22:53:35 +01:00
|
|
|
mpvDefaultProfiles = with types; listOf str;
|
2019-04-30 03:25:53 +02:00
|
|
|
|
|
|
|
renderOption = option:
|
|
|
|
rec {
|
|
|
|
int = toString option;
|
|
|
|
float = int;
|
2022-04-08 06:36:13 +02:00
|
|
|
bool = lib.hm.booleans.yesNo option;
|
2019-04-30 03:25:53 +02:00
|
|
|
string = option;
|
|
|
|
}.${typeOf option};
|
|
|
|
|
2020-09-06 20:04:07 +02:00
|
|
|
renderOptionValue = value:
|
|
|
|
let
|
|
|
|
rendered = renderOption value;
|
|
|
|
length = toString (stringLength rendered);
|
|
|
|
in "%${length}%${rendered}";
|
|
|
|
|
|
|
|
renderOptions = generators.toKeyValue {
|
|
|
|
mkKeyValue =
|
|
|
|
generators.mkKeyValueDefault { mkValueString = renderOptionValue; } "=";
|
|
|
|
listsAsDuplicateKeys = true;
|
|
|
|
};
|
|
|
|
|
2023-03-21 11:33:36 +01:00
|
|
|
renderScriptOptions = generators.toKeyValue {
|
|
|
|
mkKeyValue =
|
|
|
|
generators.mkKeyValueDefault { mkValueString = renderOption; } "=";
|
|
|
|
listsAsDuplicateKeys = true;
|
|
|
|
};
|
|
|
|
|
2020-09-06 20:04:07 +02:00
|
|
|
renderProfiles = generators.toINI {
|
|
|
|
mkKeyValue =
|
|
|
|
generators.mkKeyValueDefault { mkValueString = renderOptionValue; } "=";
|
|
|
|
listsAsDuplicateKeys = true;
|
|
|
|
};
|
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
|
|
|
|
2021-01-11 22:53:35 +01:00
|
|
|
renderDefaultProfiles = profiles:
|
|
|
|
renderOptions { profile = concatStringsSep "," profiles; };
|
|
|
|
|
2020-08-29 00:08:01 +02:00
|
|
|
mpvPackage = if cfg.scripts == [ ] then
|
2021-01-22 00:10:12 +01:00
|
|
|
cfg.package
|
2024-06-11 23:35:34 +02:00
|
|
|
else if hasAttr "wrapMpv" pkgs then
|
|
|
|
pkgs.wrapMpv pkgs.mpv-unwrapped { scripts = cfg.scripts; }
|
2020-08-29 00:08:01 +02:00
|
|
|
else
|
2024-06-11 23:35:34 +02:00
|
|
|
pkgs.mpv.override { scripts = cfg.scripts; };
|
2020-08-29 00:08:01 +02:00
|
|
|
|
2019-04-30 03:25:53 +02:00
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
programs.mpv = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "mpv";
|
2019-04-30 03:25:53 +02:00
|
|
|
|
2020-08-29 00:08:01 +02:00
|
|
|
package = mkOption {
|
2021-01-22 00:10:12 +01:00
|
|
|
type = types.package;
|
|
|
|
default = pkgs.mpv;
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression
|
2021-01-22 00:10:12 +01:00
|
|
|
"pkgs.wrapMpv (pkgs.mpv-unwrapped.override { vapoursynthSupport = true; }) { youtubeSupport = true; }";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-01-22 00:10:12 +01:00
|
|
|
Package providing mpv.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
finalPackage = mkOption {
|
2020-08-29 00:08:01 +02:00
|
|
|
type = types.package;
|
|
|
|
readOnly = true;
|
2021-01-22 00:10:12 +01:00
|
|
|
visible = false;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2020-08-29 00:08:01 +02:00
|
|
|
Resulting mpv package.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-09-02 17:52:02 +02:00
|
|
|
scripts = mkOption {
|
2022-07-04 16:53:07 +02:00
|
|
|
type = with types; listOf package;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = [ ];
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression "[ pkgs.mpvScripts.mpris ]";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2019-09-02 17:52:02 +02:00
|
|
|
List of scripts to use with mpv.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-03-21 11:33:36 +01:00
|
|
|
scriptOpts = mkOption {
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-03-21 11:33:36 +01:00
|
|
|
Script options added to
|
2023-07-01 01:30:13 +02:00
|
|
|
{file}`$XDG_CONFIG_HOME/mpv/script-opts/`. See
|
|
|
|
{manpage}`mpv(1)`
|
2023-03-21 11:33:36 +01:00
|
|
|
for the full list of options of builtin scripts.
|
|
|
|
'';
|
|
|
|
type = types.attrsOf mpvOptions;
|
|
|
|
default = { };
|
|
|
|
example = {
|
|
|
|
osc = {
|
|
|
|
scalewindowed = 2.0;
|
|
|
|
vidscale = false;
|
|
|
|
visibility = "always";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-04-30 03:25:53 +02:00
|
|
|
config = mkOption {
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2019-04-30 03:25:53 +02:00
|
|
|
Configuration written to
|
2023-07-01 01:30:13 +02:00
|
|
|
{file}`$XDG_CONFIG_HOME/mpv/mpv.conf`. See
|
|
|
|
{manpage}`mpv(1)`
|
2019-04-30 03:25:53 +02:00
|
|
|
for the full list of options.
|
|
|
|
'';
|
|
|
|
type = mpvOptions;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = { };
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2019-04-30 03:25:53 +02:00
|
|
|
{
|
|
|
|
profile = "gpu-hq";
|
2021-01-22 00:10:12 +01:00
|
|
|
force-window = true;
|
2019-04-30 03:25:53 +02:00
|
|
|
ytdl-format = "bestvideo+bestaudio";
|
|
|
|
cache-default = 4000000;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
profiles = mkOption {
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2019-04-30 03:25:53 +02:00
|
|
|
Sub-configuration options for specific profiles written to
|
2023-07-01 01:30:13 +02:00
|
|
|
{file}`$XDG_CONFIG_HOME/mpv/mpv.conf`. See
|
|
|
|
{option}`programs.mpv.config` for more information.
|
2019-04-30 03:25:53 +02:00
|
|
|
'';
|
|
|
|
type = mpvProfiles;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = { };
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2019-04-30 03:25:53 +02:00
|
|
|
{
|
|
|
|
fast = {
|
|
|
|
vo = "vdpau";
|
|
|
|
};
|
|
|
|
"protocol.dvd" = {
|
|
|
|
profile-desc = "profile for dvd:// streams";
|
|
|
|
alang = "en";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-01-11 22:53:35 +01:00
|
|
|
defaultProfiles = mkOption {
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-01-11 22:53:35 +01:00
|
|
|
Profiles to be applied by default. Options set by them are overridden
|
2023-07-01 01:30:13 +02:00
|
|
|
by options set in [](#opt-programs.mpv.config).
|
2021-01-11 22:53:35 +01:00
|
|
|
'';
|
|
|
|
type = mpvDefaultProfiles;
|
|
|
|
default = [ ];
|
|
|
|
example = [ "gpu-hq" ];
|
|
|
|
};
|
|
|
|
|
2019-04-30 03:25:53 +02:00
|
|
|
bindings = mkOption {
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2019-04-30 03:25:53 +02:00
|
|
|
Input configuration written to
|
2023-07-01 01:30:13 +02:00
|
|
|
{file}`$XDG_CONFIG_HOME/mpv/input.conf`. See
|
|
|
|
{manpage}`mpv(1)`
|
2019-04-30 03:25:53 +02:00
|
|
|
for the full list of options.
|
|
|
|
'';
|
|
|
|
type = mpvBindings;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = { };
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2019-04-30 03:25:53 +02:00
|
|
|
{
|
|
|
|
WHEEL_UP = "seek 10";
|
|
|
|
WHEEL_DOWN = "seek -10";
|
|
|
|
"Alt+0" = "set window-scale 0.5";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2024-04-29 15:49:58 +02:00
|
|
|
|
|
|
|
extraInput = mkOption {
|
|
|
|
description = ''
|
|
|
|
Additional lines that are appended to {file}`$XDG_CONFIG_HOME/mpv/input.conf`.
|
|
|
|
See {manpage}`mpv(1)` for the full list of options.
|
|
|
|
'';
|
|
|
|
type = with types; lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
esc quit #! Quit
|
|
|
|
# script-binding uosc/video #! Video tracks
|
|
|
|
# additional comments
|
|
|
|
'';
|
|
|
|
};
|
2019-04-30 03:25:53 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
2021-01-22 00:10:12 +01:00
|
|
|
{
|
|
|
|
assertions = [{
|
|
|
|
assertion = (cfg.scripts == [ ]) || (cfg.package == pkgs.mpv);
|
|
|
|
message = ''
|
|
|
|
The programs.mpv "package" option is mutually exclusive with "scripts" option.'';
|
|
|
|
}];
|
|
|
|
}
|
2019-04-30 03:25:53 +02:00
|
|
|
{
|
2020-08-29 00:08:01 +02:00
|
|
|
home.packages = [ mpvPackage ];
|
2021-01-22 00:10:12 +01:00
|
|
|
programs.mpv.finalPackage = mpvPackage;
|
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 = ''
|
2021-01-11 22:53:35 +01:00
|
|
|
${optionalString (cfg.defaultProfiles != [ ])
|
|
|
|
(renderDefaultProfiles cfg.defaultProfiles)}
|
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
|
|
|
'';
|
|
|
|
})
|
2024-04-29 15:49:58 +02:00
|
|
|
(mkIf (cfg.bindings != { } || cfg.extraInput != "") {
|
|
|
|
xdg.configFile."mpv/input.conf".text = mkMerge [
|
|
|
|
(mkIf (cfg.bindings != { }) (renderBindings cfg.bindings))
|
|
|
|
(mkIf (cfg.extraInput != "") cfg.extraInput)
|
|
|
|
];
|
2019-04-30 03:25:53 +02:00
|
|
|
})
|
2023-03-21 11:33:36 +01:00
|
|
|
{
|
|
|
|
xdg.configFile = mapAttrs' (name: value:
|
|
|
|
nameValuePair "mpv/script-opts/${name}.conf" {
|
|
|
|
text = renderScriptOptions value;
|
|
|
|
}) cfg.scriptOpts;
|
|
|
|
}
|
2019-04-30 03:25:53 +02:00
|
|
|
]);
|
|
|
|
|
2023-03-21 11:33:36 +01:00
|
|
|
meta.maintainers = with maintainers; [ tadeokondrak thiagokokada chuangzhu ];
|
2019-04-30 03:25:53 +02:00
|
|
|
}
|