From 545af661182304bcfe29ff11dd8d70a02362e40a Mon Sep 17 00:00:00 2001 From: Olmo Kramer Date: Wed, 26 Aug 2020 21:20:54 +0200 Subject: [PATCH 1/5] ncmpcpp: add module --- .github/CODEOWNERS | 3 + modules/lib/maintainers.nix | 6 + modules/misc/news.nix | 7 + modules/modules.nix | 1 + modules/programs/ncmpcpp.nix | 142 ++++++++++++++++++ tests/default.nix | 1 + tests/modules/programs/ncmpcpp/default.nix | 5 + .../ncmpcpp-empty-settings-expected-config | 2 + .../ncmpcpp/ncmpcpp-empty-settings.nix | 19 +++ ...ncmpcpp-example-settings-expected-bindings | 16 ++ .../ncmpcpp-example-settings-expected-config | 4 + .../ncmpcpp/ncmpcpp-example-settings.nix | 60 ++++++++ .../ncmpcpp-use-mpd-config-expected-config | 2 + .../ncmpcpp/ncmpcpp-use-mpd-config.nix | 25 +++ 14 files changed, 293 insertions(+) create mode 100644 modules/programs/ncmpcpp.nix create mode 100644 tests/modules/programs/ncmpcpp/default.nix create mode 100644 tests/modules/programs/ncmpcpp/ncmpcpp-empty-settings-expected-config create mode 100644 tests/modules/programs/ncmpcpp/ncmpcpp-empty-settings.nix create mode 100644 tests/modules/programs/ncmpcpp/ncmpcpp-example-settings-expected-bindings create mode 100644 tests/modules/programs/ncmpcpp/ncmpcpp-example-settings-expected-config create mode 100644 tests/modules/programs/ncmpcpp/ncmpcpp-example-settings.nix create mode 100644 tests/modules/programs/ncmpcpp/ncmpcpp-use-mpd-config-expected-config create mode 100644 tests/modules/programs/ncmpcpp/ncmpcpp-use-mpd-config.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index dccdc8f8ec81..3aa838abd1ea 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -77,6 +77,9 @@ /modules/programs/mpv.nix @tadeokondrak +/modules/programs/ncmpcpp.nix @olmokramer +/tests/modules/programs/ncmpcpp @olmokramer + /modules/programs/ne.nix @cwyc /tests/modules/programs/ne @cwyc diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index ff046360071c..8cb8781228b3 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -35,4 +35,10 @@ fingerprint = "D446 E58D 87A0 31C7 EC15 88D7 B461 2924 45C6 E696"; }]; }; + olmokramer = { + name = "Olmo Kramer"; + email = "olmokramer@users.noreply.github.com"; + github = "olmokramer"; + githubId = 3612514; + }; } diff --git a/modules/misc/news.nix b/modules/misc/news.nix index bdbd589a501b..2539aea7db1a 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1642,6 +1642,13 @@ in A new module is available: 'programs.mcfly' ''; } + + { + time = "2020-08-26T18:47:12+00:00"; + message = '' + A new module is available: 'programs.ncmpcpp' + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index bae51d69297f..b4eb4d4027ca 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -90,6 +90,7 @@ let (loadModule ./programs/mercurial.nix { }) (loadModule ./programs/mpv.nix { }) (loadModule ./programs/msmtp.nix { }) + (loadModule ./programs/ncmpcpp.nix { }) (loadModule ./programs/ne.nix { }) (loadModule ./programs/neomutt.nix { }) (loadModule ./programs/neovim.nix { }) diff --git a/modules/programs/ncmpcpp.nix b/modules/programs/ncmpcpp.nix new file mode 100644 index 000000000000..470fe6d0d33a --- /dev/null +++ b/modules/programs/ncmpcpp.nix @@ -0,0 +1,142 @@ +{ config, lib, pkgs, ... }: + +let + inherit (lib) types mkIf mkEnableOption mkOption; + + cfg = config.programs.ncmpcpp; + + mpdCfg = config.services.mpd; + + mpdMusicDir = if cfg.mpdMusicDir == null then + mpdCfg.musicDirectory + else + toString cfg.mpdMusicDir; + + renderSettings = settings: + lib.concatStringsSep "\n" (lib.mapAttrsToList renderSetting settings); + + renderSetting = name: value: "${name}=${renderValue value}"; + + renderValue = option: + rec { + int = toString option; + bool = if option then "yes" else "no"; + string = option; + }.${builtins.typeOf option}; + + renderBindings = bindings: + lib.concatStringsSep "\n" (map renderBinding bindings); + + renderBinding = { key, command }: + lib.concatStringsSep "\n " + ([ ''def_key "${key}"'' ] ++ maybeWrapList command); + + maybeWrapList = xs: if lib.isList xs then xs else [ xs ]; + + valueType = types.oneOf [ types.bool types.int types.str ]; + + bindingType = types.submodule ({ name, config, ... }: { + options = { + key = mkOption { + type = types.str; + description = "Key to bind."; + example = "j"; + }; + + command = mkOption { + type = types.either types.str (types.listOf types.str); + description = "Command or sequence of commands to be executed."; + example = "scroll_down"; + }; + }; + }); + +in { + meta.maintainers = with lib.maintainers; [ olmokramer ]; + + options.programs.ncmpcpp = { + enable = + mkEnableOption "ncmpcpp - An ncurses Music Player Daemon (MPD) client"; + + package = mkOption { + type = types.package; + default = pkgs.ncmpcpp; + defaultText = "pkgs.ncmpcpp"; + description = "Package providing the ncmpcpp command."; + example = "pkgs.ncmpcpp.override { ... }"; + }; + + mpdMusicDir = mkOption { + type = types.nullOr types.path; + default = null; + description = '' + Value of the mpd_music_dir option. The value of + services.mpd.musicDirectory is used if set to null. + ''; + example = "~/music"; + }; + + settings = mkOption { + type = types.attrsOf valueType; + default = { }; + description = '' + Attrset from name of a setting to its value. For available options + See + + ncmpcpp + 1 + + ''; + example = lib.literalExample '' + { + ncmpcpp_directory = "~/.local/share/ncmpcpp"; + } + ''; + }; + + bindings = mkOption { + type = types.listOf bindingType; + default = [ ]; + description = "List of keybindings."; + example = lib.literalExample '' + [ + { key = "j"; command = "scroll_down"; } + { key = "k"; command = "scroll_up"; } + { key = "J"; command = [ "select_item" "scroll_down" ]; } + { key = "K"; command = [ "select_item" "scroll_up" ]; } + ] + ''; + }; + }; + + config = mkIf cfg.enable { + assertions = [ + { + assertion = cfg.mpdMusicDir != null || mpdCfg.enable; + message = "Either set programs.ncmpcpp.mpdMusicDir or enable" + + " Home manager's MPD service with services.mpd.enable to" + + " use services.mpd.musicDirectory."; + } + { + assertion = !(cfg.settings ? mpd_music_dir); + message = "ncmpcpp's mpd_music_dir setting should be configured" + + " through the programs.ncmpcpp.mpdMusicDir option."; + } + ]; + + home.packages = [ cfg.package ]; + + xdg.configFile = { + "ncmpcpp/config".text = '' + mpd_music_dir=${mpdMusicDir} + ${renderSettings cfg.settings} + ''; + + "ncmpcpp/bindings" = lib.mkIf (lib.length cfg.bindings > 0) { + text = '' + ${renderBindings cfg.bindings} + ''; + }; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 3aa0c54431f1..0ad5c34b5615 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -53,6 +53,7 @@ import nmt { ./modules/programs/lf ./modules/programs/lieer ./modules/programs/mbsync + ./modules/programs/ncmpcpp ./modules/programs/ne ./modules/programs/neomutt ./modules/programs/newsboat diff --git a/tests/modules/programs/ncmpcpp/default.nix b/tests/modules/programs/ncmpcpp/default.nix new file mode 100644 index 000000000000..354f331c773b --- /dev/null +++ b/tests/modules/programs/ncmpcpp/default.nix @@ -0,0 +1,5 @@ +{ + ncmpcpp-use-mpd-config = ./ncmpcpp-use-mpd-config.nix; + ncmpcpp-empty-settings = ./ncmpcpp-empty-settings.nix; + ncmpcpp-example-settings = ./ncmpcpp-example-settings.nix; +} diff --git a/tests/modules/programs/ncmpcpp/ncmpcpp-empty-settings-expected-config b/tests/modules/programs/ncmpcpp/ncmpcpp-empty-settings-expected-config new file mode 100644 index 000000000000..ba0a1d3e7145 --- /dev/null +++ b/tests/modules/programs/ncmpcpp/ncmpcpp-empty-settings-expected-config @@ -0,0 +1,2 @@ +mpd_music_dir=/home/user/music + diff --git a/tests/modules/programs/ncmpcpp/ncmpcpp-empty-settings.nix b/tests/modules/programs/ncmpcpp/ncmpcpp-empty-settings.nix new file mode 100644 index 000000000000..63c48a4c40c5 --- /dev/null +++ b/tests/modules/programs/ncmpcpp/ncmpcpp-empty-settings.nix @@ -0,0 +1,19 @@ +{ pkgs, ... }: + +{ + config = { + programs.ncmpcpp.enable = true; + programs.ncmpcpp.mpdMusicDir = "/home/user/music"; + + nixpkgs.overlays = + [ (self: super: { ncmpcpp = pkgs.writeScriptBin "dummy-ncmpcpp" ""; }) ]; + + nmt.script = '' + assertFileContent \ + home-files/.config/ncmpcpp/config \ + ${./ncmpcpp-empty-settings-expected-config} + + assertPathNotExists home-files/.config/ncmpcpp/bindings + ''; + }; +} diff --git a/tests/modules/programs/ncmpcpp/ncmpcpp-example-settings-expected-bindings b/tests/modules/programs/ncmpcpp/ncmpcpp-example-settings-expected-bindings new file mode 100644 index 000000000000..a73bd129ffd6 --- /dev/null +++ b/tests/modules/programs/ncmpcpp/ncmpcpp-example-settings-expected-bindings @@ -0,0 +1,16 @@ +def_key "j" + scroll_down +def_key "k" + scroll_up +def_key "J" + select_item + scroll_down +def_key "K" + select_item + scroll_up +def_key "x" + delete_playlist_items +def_key "x" + delete_browser_items +def_key "x" + delete_stored_playlist diff --git a/tests/modules/programs/ncmpcpp/ncmpcpp-example-settings-expected-config b/tests/modules/programs/ncmpcpp/ncmpcpp-example-settings-expected-config new file mode 100644 index 000000000000..4b9eafbf0dcb --- /dev/null +++ b/tests/modules/programs/ncmpcpp/ncmpcpp-example-settings-expected-config @@ -0,0 +1,4 @@ +mpd_music_dir=/home/user/music +display_volume_level=no +playlist_disable_highlight_delay=0 +user_interface=alternative diff --git a/tests/modules/programs/ncmpcpp/ncmpcpp-example-settings.nix b/tests/modules/programs/ncmpcpp/ncmpcpp-example-settings.nix new file mode 100644 index 000000000000..02a1f09c9027 --- /dev/null +++ b/tests/modules/programs/ncmpcpp/ncmpcpp-example-settings.nix @@ -0,0 +1,60 @@ +{ pkgs, ... }: + +{ + config = { + programs.ncmpcpp = { + enable = true; + mpdMusicDir = "/home/user/music"; + + settings = { + user_interface = "alternative"; + display_volume_level = false; + playlist_disable_highlight_delay = 0; + }; + + bindings = [ + { + key = "j"; + command = "scroll_down"; + } + { + key = "k"; + command = "scroll_up"; + } + { + key = "J"; + command = [ "select_item" "scroll_down" ]; + } + { + key = "K"; + command = [ "select_item" "scroll_up" ]; + } + { + key = "x"; + command = "delete_playlist_items"; + } + { + key = "x"; + command = "delete_browser_items"; + } + { + key = "x"; + command = "delete_stored_playlist"; + } + ]; + }; + + nixpkgs.overlays = + [ (self: super: { ncmpcpp = pkgs.writeScriptBin "dummy-ncmpcpp" ""; }) ]; + + nmt.script = '' + assertFileContent \ + home-files/.config/ncmpcpp/config \ + ${./ncmpcpp-example-settings-expected-config} + + assertFileContent \ + home-files/.config/ncmpcpp/bindings \ + ${./ncmpcpp-example-settings-expected-bindings} + ''; + }; +} diff --git a/tests/modules/programs/ncmpcpp/ncmpcpp-use-mpd-config-expected-config b/tests/modules/programs/ncmpcpp/ncmpcpp-use-mpd-config-expected-config new file mode 100644 index 000000000000..ba0a1d3e7145 --- /dev/null +++ b/tests/modules/programs/ncmpcpp/ncmpcpp-use-mpd-config-expected-config @@ -0,0 +1,2 @@ +mpd_music_dir=/home/user/music + diff --git a/tests/modules/programs/ncmpcpp/ncmpcpp-use-mpd-config.nix b/tests/modules/programs/ncmpcpp/ncmpcpp-use-mpd-config.nix new file mode 100644 index 000000000000..5262f0314724 --- /dev/null +++ b/tests/modules/programs/ncmpcpp/ncmpcpp-use-mpd-config.nix @@ -0,0 +1,25 @@ +{ pkgs, ... }: + +{ + config = { + programs.ncmpcpp.enable = true; + + services.mpd.enable = true; + services.mpd.musicDirectory = "/home/user/music"; + + nixpkgs.overlays = [ + (self: super: { + ncmpcpp = pkgs.writeScriptBin "dummy-ncmpcpp" ""; + mpd = pkgs.writeScriptBin "dummy-mpd" ""; + }) + ]; + + nmt.script = '' + assertFileContent \ + home-files/.config/ncmpcpp/config \ + ${./ncmpcpp-use-mpd-config-expected-config} + + assertPathNotExists home-files/.config/ncmpcpp/bindings + ''; + }; +} From a7cc0b22b4c9be15f45803932eb9e8d398772ebf Mon Sep 17 00:00:00 2001 From: Olmo Kramer Date: Sat, 29 Aug 2020 19:38:24 +0200 Subject: [PATCH 2/5] Feedback by @rycee --- modules/programs/ncmpcpp.nix | 56 +++++++++---------- .../ncmpcpp-empty-settings-expected-config | 2 - .../ncmpcpp/ncmpcpp-empty-settings.nix | 5 +- .../ncmpcpp-example-settings-expected-config | 2 +- .../ncmpcpp-use-mpd-config-expected-config | 1 - 5 files changed, 27 insertions(+), 39 deletions(-) delete mode 100644 tests/modules/programs/ncmpcpp/ncmpcpp-empty-settings-expected-config diff --git a/modules/programs/ncmpcpp.nix b/modules/programs/ncmpcpp.nix index 470fe6d0d33a..624540d6f4ed 100644 --- a/modules/programs/ncmpcpp.nix +++ b/modules/programs/ncmpcpp.nix @@ -7,18 +7,13 @@ let mpdCfg = config.services.mpd; - mpdMusicDir = if cfg.mpdMusicDir == null then - mpdCfg.musicDirectory - else - toString cfg.mpdMusicDir; - renderSettings = settings: lib.concatStringsSep "\n" (lib.mapAttrsToList renderSetting settings); renderSetting = name: value: "${name}=${renderValue value}"; renderValue = option: - rec { + { int = toString option; bool = if option then "yes" else "no"; string = option; @@ -33,7 +28,7 @@ let maybeWrapList = xs: if lib.isList xs then xs else [ xs ]; - valueType = types.oneOf [ types.bool types.int types.str ]; + valueType = with types; oneOf [ bool int str ]; bindingType = types.submodule ({ name, config, ... }: { options = { @@ -44,7 +39,7 @@ let }; command = mkOption { - type = types.either types.str (types.listOf types.str); + type = with types; either str (listOf str); description = "Command or sequence of commands to be executed."; example = "scroll_down"; }; @@ -68,10 +63,17 @@ in { mpdMusicDir = mkOption { type = types.nullOr types.path; - default = null; + default = if mpdCfg.enable then mpdCfg.musicDirectory else null; + defaultText = lib.literalExample '' + if config.services.mpd.enable then + config.services.mpd.musicDirectory + else + null + ''; description = '' - Value of the mpd_music_dir option. The value of - services.mpd.musicDirectory is used if set to null. + Value of the mpd_music_dir setting. The value of + services.mpd.musicDirectory is used as the default if + services.mpd.enable is true. ''; example = "~/music"; }; @@ -110,32 +112,24 @@ in { }; config = mkIf cfg.enable { - assertions = [ - { - assertion = cfg.mpdMusicDir != null || mpdCfg.enable; - message = "Either set programs.ncmpcpp.mpdMusicDir or enable" - + " Home manager's MPD service with services.mpd.enable to" - + " use services.mpd.musicDirectory."; - } - { - assertion = !(cfg.settings ? mpd_music_dir); - message = "ncmpcpp's mpd_music_dir setting should be configured" - + " through the programs.ncmpcpp.mpdMusicDir option."; - } + warnings = mkIf (cfg.settings ? mpd_music_dir && cfg.mpdMusicDir != null) [ + ("programs.ncmpcpp.settings.mpd_music_dir will be overridden by" + + " programs.ncmpcpp.mpdMusicDir.") ]; home.packages = [ cfg.package ]; xdg.configFile = { - "ncmpcpp/config".text = '' - mpd_music_dir=${mpdMusicDir} - ${renderSettings cfg.settings} - ''; + "ncmpcpp/config" = let + settings = cfg.settings // lib.optionalAttrs (cfg.mpdMusicDir != null) { + mpd_music_dir = toString cfg.mpdMusicDir; + }; + in mkIf (lib.length (lib.attrValues settings) > 0) { + text = renderSettings settings + "\n"; + }; - "ncmpcpp/bindings" = lib.mkIf (lib.length cfg.bindings > 0) { - text = '' - ${renderBindings cfg.bindings} - ''; + "ncmpcpp/bindings" = mkIf (lib.length cfg.bindings > 0) { + text = renderBindings cfg.bindings + "\n"; }; }; }; diff --git a/tests/modules/programs/ncmpcpp/ncmpcpp-empty-settings-expected-config b/tests/modules/programs/ncmpcpp/ncmpcpp-empty-settings-expected-config deleted file mode 100644 index ba0a1d3e7145..000000000000 --- a/tests/modules/programs/ncmpcpp/ncmpcpp-empty-settings-expected-config +++ /dev/null @@ -1,2 +0,0 @@ -mpd_music_dir=/home/user/music - diff --git a/tests/modules/programs/ncmpcpp/ncmpcpp-empty-settings.nix b/tests/modules/programs/ncmpcpp/ncmpcpp-empty-settings.nix index 63c48a4c40c5..e5134002d3e8 100644 --- a/tests/modules/programs/ncmpcpp/ncmpcpp-empty-settings.nix +++ b/tests/modules/programs/ncmpcpp/ncmpcpp-empty-settings.nix @@ -3,15 +3,12 @@ { config = { programs.ncmpcpp.enable = true; - programs.ncmpcpp.mpdMusicDir = "/home/user/music"; nixpkgs.overlays = [ (self: super: { ncmpcpp = pkgs.writeScriptBin "dummy-ncmpcpp" ""; }) ]; nmt.script = '' - assertFileContent \ - home-files/.config/ncmpcpp/config \ - ${./ncmpcpp-empty-settings-expected-config} + assertPathNotExists home-files/.config/ncmpcpp/config assertPathNotExists home-files/.config/ncmpcpp/bindings ''; diff --git a/tests/modules/programs/ncmpcpp/ncmpcpp-example-settings-expected-config b/tests/modules/programs/ncmpcpp/ncmpcpp-example-settings-expected-config index 4b9eafbf0dcb..6aedb6110e4e 100644 --- a/tests/modules/programs/ncmpcpp/ncmpcpp-example-settings-expected-config +++ b/tests/modules/programs/ncmpcpp/ncmpcpp-example-settings-expected-config @@ -1,4 +1,4 @@ -mpd_music_dir=/home/user/music display_volume_level=no +mpd_music_dir=/home/user/music playlist_disable_highlight_delay=0 user_interface=alternative diff --git a/tests/modules/programs/ncmpcpp/ncmpcpp-use-mpd-config-expected-config b/tests/modules/programs/ncmpcpp/ncmpcpp-use-mpd-config-expected-config index ba0a1d3e7145..8aa57d08f16d 100644 --- a/tests/modules/programs/ncmpcpp/ncmpcpp-use-mpd-config-expected-config +++ b/tests/modules/programs/ncmpcpp/ncmpcpp-use-mpd-config-expected-config @@ -1,2 +1 @@ mpd_music_dir=/home/user/music - From e8fad60b744f99db2b98786c1b91884384a20a69 Mon Sep 17 00:00:00 2001 From: Olmo Kramer Date: Sun, 30 Aug 2020 16:24:20 +0200 Subject: [PATCH 3/5] Second round of feedback by @rycee --- modules/programs/ncmpcpp.nix | 39 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/modules/programs/ncmpcpp.nix b/modules/programs/ncmpcpp.nix index 624540d6f4ed..8a4c92748d1c 100644 --- a/modules/programs/ncmpcpp.nix +++ b/modules/programs/ncmpcpp.nix @@ -1,14 +1,14 @@ { config, lib, pkgs, ... }: -let - inherit (lib) types mkIf mkEnableOption mkOption; +with lib; +let cfg = config.programs.ncmpcpp; mpdCfg = config.services.mpd; renderSettings = settings: - lib.concatStringsSep "\n" (lib.mapAttrsToList renderSetting settings); + concatStringsSep "\n" (mapAttrsToList renderSetting settings); renderSetting = name: value: "${name}=${renderValue value}"; @@ -19,14 +19,12 @@ let string = option; }.${builtins.typeOf option}; - renderBindings = bindings: - lib.concatStringsSep "\n" (map renderBinding bindings); + renderBindings = bindings: concatStringsSep "\n" (map renderBinding bindings); renderBinding = { key, command }: - lib.concatStringsSep "\n " - ([ ''def_key "${key}"'' ] ++ maybeWrapList command); + concatStringsSep "\n " ([ ''def_key "${key}"'' ] ++ maybeWrapList command); - maybeWrapList = xs: if lib.isList xs then xs else [ xs ]; + maybeWrapList = xs: if isList xs then xs else [ xs ]; valueType = with types; oneOf [ bool int str ]; @@ -47,24 +45,27 @@ let }); in { - meta.maintainers = with lib.maintainers; [ olmokramer ]; + meta.maintainers = with maintainers; [ olmokramer ]; options.programs.ncmpcpp = { enable = - mkEnableOption "ncmpcpp - An ncurses Music Player Daemon (MPD) client"; + mkEnableOption "ncmpcpp - an ncurses Music Player Daemon (MPD) client"; package = mkOption { type = types.package; default = pkgs.ncmpcpp; - defaultText = "pkgs.ncmpcpp"; - description = "Package providing the ncmpcpp command."; - example = "pkgs.ncmpcpp.override { ... }"; + defaultText = literalExample "pkgs.ncmpcpp"; + description = '' + Package providing the ncmpcpp command. + ''; + example = + literalExample "pkgs.ncmpcpp.override { visualizerSupport = true; }"; }; mpdMusicDir = mkOption { type = types.nullOr types.path; default = if mpdCfg.enable then mpdCfg.musicDirectory else null; - defaultText = lib.literalExample '' + defaultText = literalExample '' if config.services.mpd.enable then config.services.mpd.musicDirectory else @@ -89,7 +90,7 @@ in { 1 ''; - example = lib.literalExample '' + example = literalExample '' { ncmpcpp_directory = "~/.local/share/ncmpcpp"; } @@ -100,7 +101,7 @@ in { type = types.listOf bindingType; default = [ ]; description = "List of keybindings."; - example = lib.literalExample '' + example = literalExample '' [ { key = "j"; command = "scroll_down"; } { key = "k"; command = "scroll_up"; } @@ -121,14 +122,14 @@ in { xdg.configFile = { "ncmpcpp/config" = let - settings = cfg.settings // lib.optionalAttrs (cfg.mpdMusicDir != null) { + settings = cfg.settings // optionalAttrs (cfg.mpdMusicDir != null) { mpd_music_dir = toString cfg.mpdMusicDir; }; - in mkIf (lib.length (lib.attrValues settings) > 0) { + in mkIf (length (attrValues settings) > 0) { text = renderSettings settings + "\n"; }; - "ncmpcpp/bindings" = mkIf (lib.length cfg.bindings > 0) { + "ncmpcpp/bindings" = mkIf (length cfg.bindings > 0) { text = renderBindings cfg.bindings + "\n"; }; }; From 1af0310a175befe8abe5c5ecd9b5ae78418ab32e Mon Sep 17 00:00:00 2001 From: Olmo Kramer Date: Sun, 30 Aug 2020 23:27:57 +0200 Subject: [PATCH 4/5] Only use MPD configuration on Linux --- modules/programs/ncmpcpp.nix | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/programs/ncmpcpp.nix b/modules/programs/ncmpcpp.nix index 8a4c92748d1c..f9644d3c689c 100644 --- a/modules/programs/ncmpcpp.nix +++ b/modules/programs/ncmpcpp.nix @@ -64,16 +64,19 @@ in { mpdMusicDir = mkOption { type = types.nullOr types.path; - default = if mpdCfg.enable then mpdCfg.musicDirectory else null; + default = if pkgs.stdenv.hostPlatform.isLinux && mpdCfg.enable then + mpdCfg.musicDirectory + else + null; defaultText = literalExample '' - if config.services.mpd.enable then + if pkgs.stdenv.hostPlatform.isLinux && config.services.mpd.enable then config.services.mpd.musicDirectory else null ''; description = '' - Value of the mpd_music_dir setting. The value of - services.mpd.musicDirectory is used as the default if + Value of the mpd_music_dir setting. On Linux platforms + the value of services.mpd.musicDirectory is used as the default if services.mpd.enable is true. ''; example = "~/music"; From 42cd21e3dbfb8e332ea46db5e4a79b6a765f1d74 Mon Sep 17 00:00:00 2001 From: Olmo Kramer Date: Tue, 1 Sep 2020 19:56:55 +0200 Subject: [PATCH 5/5] Only run ncmpcpp-use-mpd-config test on Linux --- tests/default.nix | 1 + tests/modules/programs/ncmpcpp-linux/default.nix | 1 + .../ncmpcpp-use-mpd-config-expected-config | 0 .../{ncmpcpp => ncmpcpp-linux}/ncmpcpp-use-mpd-config.nix | 0 tests/modules/programs/ncmpcpp/default.nix | 1 - 5 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 tests/modules/programs/ncmpcpp-linux/default.nix rename tests/modules/programs/{ncmpcpp => ncmpcpp-linux}/ncmpcpp-use-mpd-config-expected-config (100%) rename tests/modules/programs/{ncmpcpp => ncmpcpp-linux}/ncmpcpp-use-mpd-config.nix (100%) diff --git a/tests/default.nix b/tests/default.nix index 0ad5c34b5615..45b0d83e6b82 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -82,6 +82,7 @@ import nmt { ./modules/programs/firefox ./modules/programs/getmail ./modules/services/lieer + ./modules/programs/ncmpcpp-linux ./modules/programs/rofi ./modules/programs/waybar ./modules/services/kanshi diff --git a/tests/modules/programs/ncmpcpp-linux/default.nix b/tests/modules/programs/ncmpcpp-linux/default.nix new file mode 100644 index 000000000000..b1185c852491 --- /dev/null +++ b/tests/modules/programs/ncmpcpp-linux/default.nix @@ -0,0 +1 @@ +{ ncmpcpp-use-mpd-config = ./ncmpcpp-use-mpd-config.nix; } diff --git a/tests/modules/programs/ncmpcpp/ncmpcpp-use-mpd-config-expected-config b/tests/modules/programs/ncmpcpp-linux/ncmpcpp-use-mpd-config-expected-config similarity index 100% rename from tests/modules/programs/ncmpcpp/ncmpcpp-use-mpd-config-expected-config rename to tests/modules/programs/ncmpcpp-linux/ncmpcpp-use-mpd-config-expected-config diff --git a/tests/modules/programs/ncmpcpp/ncmpcpp-use-mpd-config.nix b/tests/modules/programs/ncmpcpp-linux/ncmpcpp-use-mpd-config.nix similarity index 100% rename from tests/modules/programs/ncmpcpp/ncmpcpp-use-mpd-config.nix rename to tests/modules/programs/ncmpcpp-linux/ncmpcpp-use-mpd-config.nix diff --git a/tests/modules/programs/ncmpcpp/default.nix b/tests/modules/programs/ncmpcpp/default.nix index 354f331c773b..c150b0d82486 100644 --- a/tests/modules/programs/ncmpcpp/default.nix +++ b/tests/modules/programs/ncmpcpp/default.nix @@ -1,5 +1,4 @@ { - ncmpcpp-use-mpd-config = ./ncmpcpp-use-mpd-config.nix; ncmpcpp-empty-settings = ./ncmpcpp-empty-settings.nix; ncmpcpp-example-settings = ./ncmpcpp-example-settings.nix; }