From b1e7cddb78d8c59b2453371a9a27b2551382d162 Mon Sep 17 00:00:00 2001 From: Olmo Kramer Date: Wed, 4 Jan 2023 23:24:11 +0100 Subject: [PATCH] ncmpcpp: Allow `str` type values for `mpdMusicDir` option The default value of `programs.ncmpcpp.mpdMusicDir` is taken from `services.mpd.musicDirectory` if the mpd module is enabled, which has type `either path str`. `programs.ncmpcpp.mpdMusicDir` did not accept `str` values, though, so an error was raised when the default value was used and `services.mpd.musicDirectory` was set to a value of type `str`. This commit changes the type of `programs.ncmpcpp.mpdMusicDir` to also accept `str` to reflect the type of `services.mpd.musicDirectory`. Fixes #3560 --- modules/programs/ncmpcpp.nix | 4 +-- .../programs/ncmpcpp-linux/default.nix | 5 +++- .../ncmpcpp-issue-3560-expected-config | 1 + .../ncmpcpp-linux/ncmpcpp-issue-3560.nix | 25 +++++++++++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 tests/modules/programs/ncmpcpp-linux/ncmpcpp-issue-3560-expected-config create mode 100644 tests/modules/programs/ncmpcpp-linux/ncmpcpp-issue-3560.nix diff --git a/modules/programs/ncmpcpp.nix b/modules/programs/ncmpcpp.nix index e37849519132..5f9bd36ebc11 100644 --- a/modules/programs/ncmpcpp.nix +++ b/modules/programs/ncmpcpp.nix @@ -62,7 +62,7 @@ in { }; mpdMusicDir = mkOption { - type = types.nullOr types.path; + type = with types; nullOr (coercedTo path toString str); default = let mpdCfg = config.services.mpd; in if pkgs.stdenv.hostPlatform.isLinux && mpdCfg.enable then mpdCfg.musicDirectory @@ -123,7 +123,7 @@ in { xdg.configFile = { "ncmpcpp/config" = let settings = cfg.settings // optionalAttrs (cfg.mpdMusicDir != null) { - mpd_music_dir = toString cfg.mpdMusicDir; + mpd_music_dir = cfg.mpdMusicDir; }; in mkIf (settings != { }) { text = renderSettings settings + "\n"; }; diff --git a/tests/modules/programs/ncmpcpp-linux/default.nix b/tests/modules/programs/ncmpcpp-linux/default.nix index b1185c852491..41933927848a 100644 --- a/tests/modules/programs/ncmpcpp-linux/default.nix +++ b/tests/modules/programs/ncmpcpp-linux/default.nix @@ -1 +1,4 @@ -{ ncmpcpp-use-mpd-config = ./ncmpcpp-use-mpd-config.nix; } +{ + ncmpcpp-use-mpd-config = ./ncmpcpp-use-mpd-config.nix; + ncmpcpp-issue-3560 = ./ncmpcpp-issue-3560.nix; +} diff --git a/tests/modules/programs/ncmpcpp-linux/ncmpcpp-issue-3560-expected-config b/tests/modules/programs/ncmpcpp-linux/ncmpcpp-issue-3560-expected-config new file mode 100644 index 000000000000..24a2f3bc3bf4 --- /dev/null +++ b/tests/modules/programs/ncmpcpp-linux/ncmpcpp-issue-3560-expected-config @@ -0,0 +1 @@ +mpd_music_dir=~/music diff --git a/tests/modules/programs/ncmpcpp-linux/ncmpcpp-issue-3560.nix b/tests/modules/programs/ncmpcpp-linux/ncmpcpp-issue-3560.nix new file mode 100644 index 000000000000..ba1607ab8ca1 --- /dev/null +++ b/tests/modules/programs/ncmpcpp-linux/ncmpcpp-issue-3560.nix @@ -0,0 +1,25 @@ +{ pkgs, ... }: + +{ + config = { + # Minimal config reproducing + # https://github.com/nix-community/home-manager/issues/3560 + programs.ncmpcpp.enable = true; + + services.mpd.enable = true; + services.mpd.musicDirectory = "~/music"; + + test.stubs = { + ncmpcpp = { }; + mpd = { }; + }; + + nmt.script = '' + assertFileContent \ + home-files/.config/ncmpcpp/config \ + ${./ncmpcpp-issue-3560-expected-config} + + assertPathNotExists home-files/.config/ncmpcpp/bindings + ''; + }; +}