fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . programs . ncmpcpp ; 8 9renderSettings = settings : 10concatStringsSep "\n" ( mapAttrsToList renderSetting settings ); 11 12renderSetting = name :value :" ${ name } = ${ renderValue value } " ; 13 14renderValue = option : 15{ 16int = toString option ; 17bool = lib . hm . booleans . yesNo option ; 18string = option ; 19}.${ builtins . typeOf option }; 20 21renderBindings = bindings :concatStringsSep "\n" ( map renderBinding bindings ); 22 23renderBinding = { key , command } : 24concatStringsSep "\n " ([ ''def_key " ${ key } "'' ] ++ maybeWrapList command ); 25 26maybeWrapList = xs :if isList xs then xs else [ xs ]; 27 28valueType = with types ; oneOf [ bool int str ]; 29 30bindingType = types . submodule ({ name , config , ...} :{ 31options = { 32key = mkOption { 33type = types . str ; 34description = "Key to bind." ; 35example = "j" ; 36}; 37 38command = mkOption { 39type = with types ; either str ( listOf str ); 40description = "Command or sequence of commands to be executed." ; 41example = "scroll_down" ; 42}; 43}; 44}); 45 46in { 47meta . maintainers = [ hm . maintainers . olmokramer ]; 48 49options . programs . ncmpcpp = { 50enable = 51mkEnableOption "ncmpcpp - an ncurses Music Player Daemon (MPD) client" ; 52 53package = mkOption { 54type = types . package ; 55default = pkgs . ncmpcpp ; 56defaultText = literalExpression "pkgs.ncmpcpp" ; 57description = '' 58Package providing the `ncmpcpp` command. 59'' ; 60example = 61literalExpression "pkgs.ncmpcpp.override { visualizerSupport = true; }" ; 62}; 63 64mpdMusicDir = mkOption { 65type = with types ; nullOr ( coercedTo path toString str ); 66default = let mpdCfg = config . services . mpd ; 67in if pkgs . stdenv . hostPlatform . isLinux && mpdCfg . enable then 68mpdCfg . musicDirectory 69else 70null ; 71defaultText = literalExpression '' 72if pkgs.stdenv.hostPlatform.isLinux && config.services.mpd.enable then 73config.services.mpd.musicDirectory 74else 75null 76'' ; 77description = '' 78Value of the `mpd_music_dir` setting. On Linux platforms the 79value of {var}`services.mpd.musicDirectory` is used as the 80default if {var}`services.mpd.enable` is 81`true`. 82'' ; 83example = "~/music" ; 84}; 85 86settings = mkOption { 87type = types . attrsOf valueType ; 88default = { }; 89description = '' 90Attribute set from name of a setting to its value. For available options 91see 92{manpage}`ncmpcpp(1)`. 93'' ; 94example = { ncmpcpp_directory = "~/.local/share/ncmpcpp" ; }; 95}; 96 97bindings = mkOption { 98type = types . listOf bindingType ; 99default = [ ]; 100description = "List of keybindings." ; 101example = literalExpression '' 102[ 103{ key = "j"; command = "scroll_down"; } 104{ key = "k"; command = "scroll_up"; } 105{ key = "J"; command = [ "select_item" "scroll_down" ]; } 106{ key = "K"; command = [ "select_item" "scroll_up" ]; } 107] 108'' ; 109}; 110}; 111 112config = mkIf cfg . enable { 113warnings = mkIf ( cfg . settings ?mpd_music_dir && cfg . mpdMusicDir != null ) [ 114( "programs.ncmpcpp.settings.mpd_music_dir will be overridden by" 115+ " programs.ncmpcpp.mpdMusicDir." ) 116]; 117 118home . packages = [ cfg . package ]; 119 120xdg . configFile = { 121"ncmpcpp/config" = let 122settings = cfg . settings // optionalAttrs ( cfg . mpdMusicDir != null ) { 123mpd_music_dir = cfg . mpdMusicDir ; 124}; 125in mkIf ( settings != { }) { text = renderSettings settings + "\n" ; }; 126 127"ncmpcpp/bindings" = mkIf ( cfg . bindings != [ ]) { 128text = renderBindings cfg . bindings + "\n" ; 129}; 130}; 131}; 132}