From 2c0e3f61da903613cc316cb992c8c07d92e1d186 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Thu, 21 Jan 2021 20:10:12 -0300 Subject: [PATCH] mpv: fix issue #1725 and add tests (#1726) Closes issue #1725. This allows mpv module to be customized with support for more advanced features than the `programs.mpv.scripts` current support. For example, with this change now this is possible: ```nix { programs.mpv.package = (pkgs.wrapMpv (pkgs.mpv-unwrapped.override { vapoursynthSupport = true; }) { extraMakeWrapperArgs = [ "--prefix" "LD_LIBRARY_PATH" ":" "${pkgs.vapoursynth-mvtools}/lib/vapoursynth" ]; }); } ``` Since `programs.mpv.package` doesn't necessary reflect the final derivation anymore (see #1524), we introduce `programs.mpv.finalPackage` that has the resulting derivation. This includes 2 tests: - One to check if everything is alright with mpv - Other to validate our assertion that package and scripts can't be passed both at the same time * docs: document recent mpv module changes * mpv: add thiagokokada as maintainer --- doc/release-notes/rl-2103.adoc | 18 ++++++++ modules/lib/maintainers.nix | 6 +++ modules/programs/mpv.nix | 26 +++++++++-- tests/default.nix | 1 + tests/modules/programs/mpv/default.nix | 4 ++ .../mpv-example-settings-expected-bindings | 3 ++ .../mpv/mpv-example-settings-expected-config | 13 ++++++ .../programs/mpv/mpv-example-settings.nix | 46 +++++++++++++++++++ .../mpv/mpv-invalid-settings-expected.json | 1 + .../programs/mpv/mpv-invalid-settings.nix | 29 ++++++++++++ 10 files changed, 143 insertions(+), 4 deletions(-) create mode 100644 tests/modules/programs/mpv/default.nix create mode 100644 tests/modules/programs/mpv/mpv-example-settings-expected-bindings create mode 100644 tests/modules/programs/mpv/mpv-example-settings-expected-config create mode 100644 tests/modules/programs/mpv/mpv-example-settings.nix create mode 100644 tests/modules/programs/mpv/mpv-invalid-settings-expected.json create mode 100644 tests/modules/programs/mpv/mpv-invalid-settings.nix diff --git a/doc/release-notes/rl-2103.adoc b/doc/release-notes/rl-2103.adoc index 7d5b55d4..599af75f 100644 --- a/doc/release-notes/rl-2103.adoc +++ b/doc/release-notes/rl-2103.adoc @@ -32,6 +32,24 @@ programs.broot.verbs = [ ]; ---- +* The <> option has been changed to allow custom +derivations. The following configuration is now possible: ++ +[source,nix] +---- +programs.mpv.package = (pkgs.wrapMpv (pkgs.mpv-unwrapped.override { + vapoursynthSupport = true; +}) { + extraMakeWrapperArgs = [ + "--prefix" "LD_LIBRARY_PATH" ":" "${pkgs.vapoursynth-mvtools}/lib/vapoursynth" + ]; +}); +---- ++ +As a result of this change, <> is no longer the +resulting derivation. Use the newly introduced `programs.mpv.finalPackage` +instead. + [[sec-release-21.03-state-version-changes]] === State Version Changes diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index de180801..680549cf 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -47,4 +47,10 @@ fingerprint = "F0E0 0311 126A CD72 4392 25E6 68BF 2EAE 6D91 CAFF"; }]; }; + thiagokokada = { + email = "thiagokokada@gmail.com"; + name = "Thiago Kenji Okada"; + github = "thiagokokada"; + githubId = 844343; + }; } diff --git a/modules/programs/mpv.nix b/modules/programs/mpv.nix index 938435f3..ab822511 100644 --- a/modules/programs/mpv.nix +++ b/modules/programs/mpv.nix @@ -50,7 +50,7 @@ let renderOptions { profile = concatStringsSep "," profiles; }; mpvPackage = if cfg.scripts == [ ] then - pkgs.mpv + cfg.package else pkgs.wrapMpv pkgs.mpv-unwrapped { scripts = cfg.scripts; }; @@ -60,8 +60,19 @@ in { enable = mkEnableOption "mpv"; package = mkOption { + type = types.package; + default = pkgs.mpv; + example = literalExample + "pkgs.wrapMpv (pkgs.mpv-unwrapped.override { vapoursynthSupport = true; }) { youtubeSupport = true; }"; + description = '' + Package providing mpv. + ''; + }; + + finalPackage = mkOption { type = types.package; readOnly = true; + visible = false; description = '' Resulting mpv package. ''; @@ -91,7 +102,7 @@ in { example = literalExample '' { profile = "gpu-hq"; - force-window = "yes"; + force-window = true; ytdl-format = "bestvideo+bestaudio"; cache-default = 4000000; } @@ -153,9 +164,16 @@ in { }; config = mkIf cfg.enable (mkMerge [ + { + assertions = [{ + assertion = (cfg.scripts == [ ]) || (cfg.package == pkgs.mpv); + message = '' + The programs.mpv "package" option is mutually exclusive with "scripts" option.''; + }]; + } { home.packages = [ mpvPackage ]; - programs.mpv.package = mpvPackage; + programs.mpv.finalPackage = mpvPackage; } (mkIf (cfg.config != { } || cfg.profiles != { }) { xdg.configFile."mpv/mpv.conf".text = '' @@ -170,5 +188,5 @@ in { }) ]); - meta.maintainers = with maintainers; [ tadeokondrak ]; + meta.maintainers = with maintainers; [ tadeokondrak thiagokokada ]; } diff --git a/tests/default.nix b/tests/default.nix index 33a22e2b..ce395f54 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -59,6 +59,7 @@ import nmt { ./modules/programs/lieer ./modules/programs/man ./modules/programs/mbsync + ./modules/programs/mpv ./modules/programs/ncmpcpp ./modules/programs/ne ./modules/programs/neomutt diff --git a/tests/modules/programs/mpv/default.nix b/tests/modules/programs/mpv/default.nix new file mode 100644 index 00000000..c2785ed3 --- /dev/null +++ b/tests/modules/programs/mpv/default.nix @@ -0,0 +1,4 @@ +{ + mpv-example-settings = ./mpv-example-settings.nix; + mpv-invalid-settings = ./mpv-invalid-settings.nix; +} diff --git a/tests/modules/programs/mpv/mpv-example-settings-expected-bindings b/tests/modules/programs/mpv/mpv-example-settings-expected-bindings new file mode 100644 index 00000000..7a2ee13b --- /dev/null +++ b/tests/modules/programs/mpv/mpv-example-settings-expected-bindings @@ -0,0 +1,3 @@ +Alt+0 set window-scale 0.5 +WHEEL_DOWN seek -10 +WHEEL_UP seek 10 \ No newline at end of file diff --git a/tests/modules/programs/mpv/mpv-example-settings-expected-config b/tests/modules/programs/mpv/mpv-example-settings-expected-config new file mode 100644 index 00000000..e4423909 --- /dev/null +++ b/tests/modules/programs/mpv/mpv-example-settings-expected-config @@ -0,0 +1,13 @@ +profile=%6%gpu-hq + +cache-default=%7%4000000 +force-window=%3%yes +ytdl-format=%19%bestvideo+bestaudio + +[fast] +vo=%5%vdpau + +[protocol.dvd] +alang=%2%en +profile-desc=%26%profile for dvd:// streams + diff --git a/tests/modules/programs/mpv/mpv-example-settings.nix b/tests/modules/programs/mpv/mpv-example-settings.nix new file mode 100644 index 00000000..5701d9ea --- /dev/null +++ b/tests/modules/programs/mpv/mpv-example-settings.nix @@ -0,0 +1,46 @@ +{ config, lib, pkgs, ... }: + +{ + config = { + programs.mpv = { + enable = true; + package = pkgs.mpvDummy; + + bindings = { + WHEEL_UP = "seek 10"; + WHEEL_DOWN = "seek -10"; + "Alt+0" = "set window-scale 0.5"; + }; + + config = { + force-window = true; + ytdl-format = "bestvideo+bestaudio"; + cache-default = 4000000; + }; + + profiles = { + fast = { vo = "vdpau"; }; + "protocol.dvd" = { + profile-desc = "profile for dvd:// streams"; + alang = "en"; + }; + }; + + defaultProfiles = [ "gpu-hq" ]; + }; + + nixpkgs.overlays = [ + (self: super: { mpvDummy = pkgs.runCommandLocal "mpv" { } "mkdir $out"; }) + ]; + + nmt.script = '' + assertFileContent \ + home-files/.config/mpv/mpv.conf \ + ${./mpv-example-settings-expected-config} + assertFileContent \ + home-files/.config/mpv/input.conf \ + ${./mpv-example-settings-expected-bindings} + ''; + }; + +} diff --git a/tests/modules/programs/mpv/mpv-invalid-settings-expected.json b/tests/modules/programs/mpv/mpv-invalid-settings-expected.json new file mode 100644 index 00000000..50d6f6f5 --- /dev/null +++ b/tests/modules/programs/mpv/mpv-invalid-settings-expected.json @@ -0,0 +1 @@ +["The programs.mpv \"package\" option is mutually exclusive with \"scripts\" option."] \ No newline at end of file diff --git a/tests/modules/programs/mpv/mpv-invalid-settings.nix b/tests/modules/programs/mpv/mpv-invalid-settings.nix new file mode 100644 index 00000000..40cd4529 --- /dev/null +++ b/tests/modules/programs/mpv/mpv-invalid-settings.nix @@ -0,0 +1,29 @@ +{ config, lib, pkgs, ... }: + +{ + config = { + programs.mpv = { + enable = true; + package = pkgs.mpvDummy; + scripts = [ pkgs.mpvScript ]; + }; + + nixpkgs.overlays = [ + (self: super: { + mpvDummy = pkgs.runCommandLocal "mpv" { } "mkdir $out"; + mpvScript = + pkgs.runCommandLocal "mpvScript" { scriptName = "something"; } + "mkdir $out"; + }) + ]; + + home.file.result.text = builtins.toJSON + (map (a: a.message) (lib.filter (a: !a.assertion) config.assertions)); + + nmt.script = '' + assertFileContent \ + home-files/result \ + ${./mpv-invalid-settings-expected.json} + ''; + }; +}