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
This commit is contained in:
Thiago Kenji Okada 2021-01-21 20:10:12 -03:00 committed by GitHub
parent 5280360d6c
commit 2c0e3f61da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 143 additions and 4 deletions

View File

@ -32,6 +32,24 @@ programs.broot.verbs = [
];
----
* The <<opt-programs.mpv.package>> 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, <<opt-programs.mpv.package>> is no longer the
resulting derivation. Use the newly introduced `programs.mpv.finalPackage`
instead.
[[sec-release-21.03-state-version-changes]]
=== State Version Changes

View File

@ -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;
};
}

View File

@ -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 ];
}

View File

@ -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

View File

@ -0,0 +1,4 @@
{
mpv-example-settings = ./mpv-example-settings.nix;
mpv-invalid-settings = ./mpv-invalid-settings.nix;
}

View File

@ -0,0 +1,3 @@
Alt+0 set window-scale 0.5
WHEEL_DOWN seek -10
WHEEL_UP seek 10

View File

@ -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

View File

@ -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}
'';
};
}

View File

@ -0,0 +1 @@
["The programs.mpv \"package\" option is mutually exclusive with \"scripts\" option."]

View File

@ -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}
'';
};
}