From 7abcf59a365430b36f84eaa452a466b11e469e33 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron <886074+teto@users.noreply.github.com> Date: Tue, 4 Feb 2025 12:07:35 +0100 Subject: [PATCH] mpv: support includes directives (#6391) to allow mixing imperative and declarative config the includes are at the end of the config --- modules/programs/mpv.nix | 21 +++++++++++++++++++ .../mpv/mpv-example-settings-expected-config | 2 ++ .../programs/mpv/mpv-example-settings.nix | 2 ++ 3 files changed, 25 insertions(+) diff --git a/modules/programs/mpv.nix b/modules/programs/mpv.nix index f2664e71a..e8bcc1446 100644 --- a/modules/programs/mpv.nix +++ b/modules/programs/mpv.nix @@ -130,6 +130,19 @@ in { ''; }; + includes = mkOption { + type = types.listOf types.str; + default = [ ]; + example = literalExpression '' + [ + "~/path/to/config.inc"; + "~/path/to/conditional.inc"; + ] + ''; + description = + "List of configuration files to include at the end of mpv.conf."; + }; + profiles = mkOption { description = '' Sub-configuration options for specific profiles written to @@ -207,6 +220,14 @@ in { home.packages = [ mpvPackage ]; programs.mpv.finalPackage = mpvPackage; } + + (mkIf (cfg.includes != [ ]) { + xdg.configFile."mpv/mpv.conf" = { + text = lib.mkAfter + (concatMapStringsSep "\n" (x: "include=${x}") cfg.includes); + }; + }) + (mkIf (cfg.config != { } || cfg.profiles != { }) { xdg.configFile."mpv/mpv.conf".text = '' ${optionalString (cfg.defaultProfiles != [ ]) diff --git a/tests/modules/programs/mpv/mpv-example-settings-expected-config b/tests/modules/programs/mpv/mpv-example-settings-expected-config index e44239096..4f4c3cd2d 100644 --- a/tests/modules/programs/mpv/mpv-example-settings-expected-config +++ b/tests/modules/programs/mpv/mpv-example-settings-expected-config @@ -11,3 +11,5 @@ vo=%5%vdpau alang=%2%en profile-desc=%26%profile for dvd:// streams + +include=manual.conf \ No newline at end of file diff --git a/tests/modules/programs/mpv/mpv-example-settings.nix b/tests/modules/programs/mpv/mpv-example-settings.nix index 002e071c1..2fc5ca5de 100644 --- a/tests/modules/programs/mpv/mpv-example-settings.nix +++ b/tests/modules/programs/mpv/mpv-example-settings.nix @@ -16,6 +16,8 @@ # script-binding uosc/video #! Video tracks ''; + includes = [ "manual.conf" ]; + config = { force-window = true; ytdl-format = "bestvideo+bestaudio";