From e386ec640e16dc91120977285cb8c72c77078164 Mon Sep 17 00:00:00 2001 From: Chuang Zhu Date: Tue, 21 Mar 2023 18:33:36 +0800 Subject: [PATCH] mpv: add scriptOpts option, fix tests (#3491) --- .github/CODEOWNERS | 4 +-- modules/programs/mpv.nix | 35 ++++++++++++++++++- tests/modules/programs/mpv/default.nix | 4 +-- .../mpv-example-settings-expected-osc-opts | 3 ++ .../programs/mpv/mpv-example-settings.nix | 11 ++++++ .../programs/mpv/mpv-invalid-settings.nix | 14 +------- 6 files changed, 53 insertions(+), 18 deletions(-) create mode 100644 tests/modules/programs/mpv/mpv-example-settings-expected-osc-opts diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 746db5528..e4f70fd61 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -203,8 +203,8 @@ Makefile @thiagokokada /modules/programs/micro.nix @MForster /tests/modules/programs/micro @MForster -/modules/programs/mpv.nix @tadeokondrak @thiagokokada -/tests/modules/programs/mpv @thiagokokada +/modules/programs/mpv.nix @tadeokondrak @thiagokokada @chuangzhu +/tests/modules/programs/mpv @thiagokokada @chuangzhu /modules/programs/mu.nix @KarlJoad diff --git a/modules/programs/mpv.nix b/modules/programs/mpv.nix index 47413490d..1d0b24d40 100644 --- a/modules/programs/mpv.nix +++ b/modules/programs/mpv.nix @@ -34,6 +34,12 @@ let listsAsDuplicateKeys = true; }; + renderScriptOptions = generators.toKeyValue { + mkKeyValue = + generators.mkKeyValueDefault { mkValueString = renderOption; } "="; + listsAsDuplicateKeys = true; + }; + renderProfiles = generators.toINI { mkKeyValue = generators.mkKeyValueDefault { mkValueString = renderOptionValue; } "="; @@ -85,6 +91,27 @@ in { ''; }; + scriptOpts = mkOption { + description = '' + Script options added to + $XDG_CONFIG_HOME/mpv/script-opts/. See + + mpv + 1 + + for the full list of options of builtin scripts. + ''; + type = types.attrsOf mpvOptions; + default = { }; + example = { + osc = { + scalewindowed = 2.0; + vidscale = false; + visibility = "always"; + }; + }; + }; + config = mkOption { description = '' Configuration written to @@ -184,7 +211,13 @@ in { (mkIf (cfg.bindings != { }) { xdg.configFile."mpv/input.conf".text = renderBindings cfg.bindings; }) + { + xdg.configFile = mapAttrs' (name: value: + nameValuePair "mpv/script-opts/${name}.conf" { + text = renderScriptOptions value; + }) cfg.scriptOpts; + } ]); - meta.maintainers = with maintainers; [ tadeokondrak thiagokokada ]; + meta.maintainers = with maintainers; [ tadeokondrak thiagokokada chuangzhu ]; } diff --git a/tests/modules/programs/mpv/default.nix b/tests/modules/programs/mpv/default.nix index 6e071610f..66932b0b2 100644 --- a/tests/modules/programs/mpv/default.nix +++ b/tests/modules/programs/mpv/default.nix @@ -1,5 +1,5 @@ { # Temporarily commented until fixed for recent changes in Nixpkgs. - # mpv-example-settings = ./mpv-example-settings.nix; - # mpv-invalid-settings = ./mpv-invalid-settings.nix; + 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-osc-opts b/tests/modules/programs/mpv/mpv-example-settings-expected-osc-opts new file mode 100644 index 000000000..db377967b --- /dev/null +++ b/tests/modules/programs/mpv/mpv-example-settings-expected-osc-opts @@ -0,0 +1,3 @@ +scalewindowed=2.000000 +vidscale=no +visibility=always diff --git a/tests/modules/programs/mpv/mpv-example-settings.nix b/tests/modules/programs/mpv/mpv-example-settings.nix index 9bb53e57d..58467de0b 100644 --- a/tests/modules/programs/mpv/mpv-example-settings.nix +++ b/tests/modules/programs/mpv/mpv-example-settings.nix @@ -18,6 +18,14 @@ cache-default = 4000000; }; + scriptOpts = { + osc = { + scalewindowed = 2.0; + vidscale = false; + visibility = "always"; + }; + }; + profiles = { fast = { vo = "vdpau"; }; "protocol.dvd" = { @@ -38,6 +46,9 @@ assertFileContent \ home-files/.config/mpv/input.conf \ ${./mpv-example-settings-expected-bindings} + assertFileContent \ + home-files/.config/mpv/script-opts/osc.conf \ + ${./mpv-example-settings-expected-osc-opts} ''; }; diff --git a/tests/modules/programs/mpv/mpv-invalid-settings.nix b/tests/modules/programs/mpv/mpv-invalid-settings.nix index 1c4a80c11..701c823fb 100644 --- a/tests/modules/programs/mpv/mpv-invalid-settings.nix +++ b/tests/modules/programs/mpv/mpv-invalid-settings.nix @@ -10,24 +10,12 @@ nixpkgs.overlays = [ (self: super: { - mpv-unwrapped = pkgs.runCommandLocal "mpv" { - version = "0"; - passthru = { - lua.luaversion = "0"; - luaEnv = "/dummy"; - vapoursynthSupport = false; - }; - } '' - mkdir -p $out/bin $out/Applications/mpv.app/Contents/MacOS - touch $out/bin/{,u}mpv $out/Applications/mpv.app/Contents/MacOS/mpv - chmod 755 $out/bin/{,u}mpv $out/Applications/mpv.app/Contents/MacOS/mpv - ''; - mpvDummy = config.lib.test.mkStubPackage { }; mpvScript = pkgs.runCommandLocal "mpvScript" { scriptName = "something"; } "mkdir $out"; }) ]; + test.stubs.mpvDummy = { }; test.asserts.assertions.expected = [ ''