2020-08-26 21:20:54 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.ncmpcpp;
|
|
|
|
|
|
|
|
renderSettings = settings:
|
|
|
|
concatStringsSep "\n" (mapAttrsToList renderSetting settings);
|
|
|
|
|
|
|
|
renderSetting = name: value: "${name}=${renderValue value}";
|
|
|
|
|
|
|
|
renderValue = option:
|
|
|
|
{
|
|
|
|
int = toString option;
|
2022-04-08 06:36:13 +02:00
|
|
|
bool = lib.hm.booleans.yesNo option;
|
2020-08-26 21:20:54 +02:00
|
|
|
string = option;
|
|
|
|
}.${builtins.typeOf option};
|
|
|
|
|
|
|
|
renderBindings = bindings: concatStringsSep "\n" (map renderBinding bindings);
|
|
|
|
|
|
|
|
renderBinding = { key, command }:
|
|
|
|
concatStringsSep "\n " ([ ''def_key "${key}"'' ] ++ maybeWrapList command);
|
|
|
|
|
|
|
|
maybeWrapList = xs: if isList xs then xs else [ xs ];
|
|
|
|
|
|
|
|
valueType = with types; oneOf [ bool int str ];
|
|
|
|
|
|
|
|
bindingType = types.submodule ({ name, config, ... }: {
|
|
|
|
options = {
|
|
|
|
key = mkOption {
|
|
|
|
type = types.str;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Key to bind.";
|
2020-08-26 21:20:54 +02:00
|
|
|
example = "j";
|
|
|
|
};
|
|
|
|
|
|
|
|
command = mkOption {
|
|
|
|
type = with types; either str (listOf str);
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Command or sequence of commands to be executed.";
|
2020-08-26 21:20:54 +02:00
|
|
|
example = "scroll_down";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
in {
|
2021-12-25 19:33:09 +01:00
|
|
|
meta.maintainers = [ hm.maintainers.olmokramer ];
|
2020-08-26 21:20:54 +02:00
|
|
|
|
|
|
|
options.programs.ncmpcpp = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable =
|
|
|
|
mkEnableOption "ncmpcpp - an ncurses Music Player Daemon (MPD) client";
|
2020-08-26 21:20:54 +02:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.ncmpcpp;
|
2021-10-09 11:14:08 +02:00
|
|
|
defaultText = literalExpression "pkgs.ncmpcpp";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
Package providing the `ncmpcpp` command.
|
2020-08-26 21:20:54 +02:00
|
|
|
'';
|
|
|
|
example =
|
2021-10-09 11:14:08 +02:00
|
|
|
literalExpression "pkgs.ncmpcpp.override { visualizerSupport = true; }";
|
2020-08-26 21:20:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
mpdMusicDir = mkOption {
|
2023-01-07 11:59:51 +01:00
|
|
|
type = with types; nullOr (coercedTo path toString str);
|
2020-08-26 21:20:54 +02:00
|
|
|
default = let mpdCfg = config.services.mpd;
|
|
|
|
in if pkgs.stdenv.hostPlatform.isLinux && mpdCfg.enable then
|
|
|
|
mpdCfg.musicDirectory
|
|
|
|
else
|
|
|
|
null;
|
2021-10-09 11:14:08 +02:00
|
|
|
defaultText = literalExpression ''
|
2020-08-26 21:20:54 +02:00
|
|
|
if pkgs.stdenv.hostPlatform.isLinux && config.services.mpd.enable then
|
|
|
|
config.services.mpd.musicDirectory
|
|
|
|
else
|
|
|
|
null
|
|
|
|
'';
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
Value of the `mpd_music_dir` setting. On Linux platforms the
|
|
|
|
value of {var}`services.mpd.musicDirectory` is used as the
|
|
|
|
default if {var}`services.mpd.enable` is
|
|
|
|
`true`.
|
2020-08-26 21:20:54 +02:00
|
|
|
'';
|
|
|
|
example = "~/music";
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = types.attrsOf valueType;
|
|
|
|
default = { };
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2020-08-26 21:20:54 +02:00
|
|
|
Attribute set from name of a setting to its value. For available options
|
|
|
|
see
|
2023-07-01 01:30:13 +02:00
|
|
|
{manpage}`ncmpcpp(1)`.
|
2020-08-26 21:20:54 +02:00
|
|
|
'';
|
|
|
|
example = { ncmpcpp_directory = "~/.local/share/ncmpcpp"; };
|
|
|
|
};
|
|
|
|
|
|
|
|
bindings = mkOption {
|
|
|
|
type = types.listOf bindingType;
|
|
|
|
default = [ ];
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "List of keybindings.";
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2020-08-26 21:20:54 +02:00
|
|
|
[
|
|
|
|
{ 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 {
|
|
|
|
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" = let
|
|
|
|
settings = cfg.settings // optionalAttrs (cfg.mpdMusicDir != null) {
|
2023-01-07 11:59:51 +01:00
|
|
|
mpd_music_dir = cfg.mpdMusicDir;
|
2020-08-26 21:20:54 +02:00
|
|
|
};
|
|
|
|
in mkIf (settings != { }) { text = renderSettings settings + "\n"; };
|
|
|
|
|
|
|
|
"ncmpcpp/bindings" = mkIf (cfg.bindings != [ ]) {
|
|
|
|
text = renderBindings cfg.bindings + "\n";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|