-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ncmpcpp: add module #1457
Closed
Closed
ncmpcpp: add module #1457
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
545af66
ncmpcpp: add module
olmokramer a7cc0b2
Feedback by @rycee
olmokramer e8fad60
Second round of feedback by @rycee
olmokramer 1af0310
Only use MPD configuration on Linux
olmokramer 42cd21e
Only run ncmpcpp-use-mpd-config test on Linux
olmokramer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,10 @@ | |
fingerprint = "D446 E58D 87A0 31C7 EC15 88D7 B461 2924 45C6 E696"; | ||
}]; | ||
}; | ||
olmokramer = { | ||
name = "Olmo Kramer"; | ||
email = "[email protected]"; | ||
github = "olmokramer"; | ||
githubId = 3612514; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
with lib; | ||
|
||
let | ||
cfg = config.programs.ncmpcpp; | ||
|
||
mpdCfg = config.services.mpd; | ||
|
||
renderSettings = settings: | ||
concatStringsSep "\n" (mapAttrsToList renderSetting settings); | ||
|
||
renderSetting = name: value: "${name}=${renderValue value}"; | ||
|
||
renderValue = option: | ||
{ | ||
int = toString option; | ||
bool = if option then "yes" else "no"; | ||
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; | ||
description = "Key to bind."; | ||
example = "j"; | ||
}; | ||
|
||
command = mkOption { | ||
type = with types; either str (listOf str); | ||
description = "Command or sequence of commands to be executed."; | ||
example = "scroll_down"; | ||
}; | ||
}; | ||
}); | ||
|
||
in { | ||
meta.maintainers = with maintainers; [ olmokramer ]; | ||
|
||
options.programs.ncmpcpp = { | ||
enable = | ||
mkEnableOption "ncmpcpp - an ncurses Music Player Daemon (MPD) client"; | ||
|
||
package = mkOption { | ||
type = types.package; | ||
default = pkgs.ncmpcpp; | ||
defaultText = literalExample "pkgs.ncmpcpp"; | ||
description = '' | ||
Package providing the <code>ncmpcpp</code> command. | ||
''; | ||
example = | ||
literalExample "pkgs.ncmpcpp.override { visualizerSupport = true; }"; | ||
}; | ||
|
||
mpdMusicDir = mkOption { | ||
type = types.nullOr types.path; | ||
default = if pkgs.stdenv.hostPlatform.isLinux && mpdCfg.enable then | ||
mpdCfg.musicDirectory | ||
else | ||
null; | ||
defaultText = literalExample '' | ||
if pkgs.stdenv.hostPlatform.isLinux && config.services.mpd.enable then | ||
config.services.mpd.musicDirectory | ||
else | ||
null | ||
''; | ||
description = '' | ||
Value of the <code>mpd_music_dir</code> setting. On Linux platforms | ||
the value of services.mpd.musicDirectory is used as the default if | ||
services.mpd.enable is <literal>true</literal>. | ||
''; | ||
example = "~/music"; | ||
}; | ||
|
||
settings = mkOption { | ||
type = types.attrsOf valueType; | ||
default = { }; | ||
description = '' | ||
Attrset from name of a setting to its value. For available options | ||
See | ||
<citerefentry> | ||
<refentrytitle>ncmpcpp</refentrytitle> | ||
<manvolnum>1</manvolnum> | ||
</citerefentry> | ||
''; | ||
example = literalExample '' | ||
{ | ||
ncmpcpp_directory = "~/.local/share/ncmpcpp"; | ||
} | ||
''; | ||
}; | ||
|
||
bindings = mkOption { | ||
type = types.listOf bindingType; | ||
rycee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
default = [ ]; | ||
description = "List of keybindings."; | ||
example = 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 { | ||
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) { | ||
mpd_music_dir = toString cfg.mpdMusicDir; | ||
}; | ||
in mkIf (length (attrValues settings) > 0) { | ||
text = renderSettings settings + "\n"; | ||
}; | ||
|
||
"ncmpcpp/bindings" = mkIf (length cfg.bindings > 0) { | ||
text = renderBindings cfg.bindings + "\n"; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ ncmpcpp-use-mpd-config = ./ncmpcpp-use-mpd-config.nix; } |
1 change: 1 addition & 0 deletions
1
tests/modules/programs/ncmpcpp-linux/ncmpcpp-use-mpd-config-expected-config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mpd_music_dir=/home/user/music |
25 changes: 25 additions & 0 deletions
25
tests/modules/programs/ncmpcpp-linux/ncmpcpp-use-mpd-config.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
''; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
ncmpcpp-empty-settings = ./ncmpcpp-empty-settings.nix; | ||
ncmpcpp-example-settings = ./ncmpcpp-example-settings.nix; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ pkgs, ... }: | ||
|
||
{ | ||
config = { | ||
programs.ncmpcpp.enable = true; | ||
|
||
nixpkgs.overlays = | ||
[ (self: super: { ncmpcpp = pkgs.writeScriptBin "dummy-ncmpcpp" ""; }) ]; | ||
|
||
nmt.script = '' | ||
assertPathNotExists home-files/.config/ncmpcpp/config | ||
|
||
assertPathNotExists home-files/.config/ncmpcpp/bindings | ||
''; | ||
}; | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/modules/programs/ncmpcpp/ncmpcpp-example-settings-expected-bindings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
4 changes: 4 additions & 0 deletions
4
tests/modules/programs/ncmpcpp/ncmpcpp-example-settings-expected-config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
display_volume_level=no | ||
mpd_music_dir=/home/user/music | ||
playlist_disable_highlight_delay=0 | ||
user_interface=alternative |
60 changes: 60 additions & 0 deletions
60
tests/modules/programs/ncmpcpp/ncmpcpp-example-settings.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} | ||
''; | ||
}; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could get rid of this option and place it under
settings
ifsettings
were a freeform module, but that breaks the tests with an error:The Freeform modules PR has only been merged 12 days ago, though, so it may not be a great idea to start relying on it already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what that might look like https://github.com/olmokramer/home-manager/blob/ncmpcpp-freeform/modules/programs/ncmpcpp.nix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. I'll have to check out 🙂