fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2let 3cfg = config . services . mpd-mpris ; 4 5ignoreIfLocalMpd = value :if cfg . mpd . useLocal then null else value ; 6 7renderArg = name :value : 8if lib . isBool value && value then 9"- ${ name } " 10else if lib . isInt value then 11"- ${ name } ${ toString value } " 12else if lib . isString value then 13"- ${ name } ${ lib . escapeShellArg value } " 14else 15"" ; 16 17concatArgs = strings : 18lib . concatStringsSep " " ( lib . filter ( s :s != "" ) strings ); 19 20renderArgs = args :concatArgs ( lib . mapAttrsToList renderArg args ); 21 22renderCmd = pkg :args :" ${ pkg } /bin/mpd-mpris ${ renderArgs args } " ; 23in { 24meta . maintainers = [ lib . hm . maintainers . olmokramer ]; 25 26options . services . mpd-mpris = { 27enable = lib . mkEnableOption 28"mpd-mpris: An implementation of the MPRIS protocol for MPD" ; 29 30package = lib . mkPackageOption pkgs "mpd-mpris" { }; 31 32mpd = { 33useLocal = lib . mkOption { 34type = lib . types . bool ; 35default = config . services . mpd . enable ; 36defaultText = lib . literalExpression "config.services.mpd.enable" ; 37description = '' 38Whether to configure for the local MPD daemon. If 39`true` the `network`, 40`host`, and `port` 41settings are ignored. 42'' ; 43}; 44 45network = lib . mkOption { 46type = with lib . types ; nullOr str ; 47default = null ; 48description = '' 49The network used to dial to the MPD server. Check 50<https://golang.org/pkg/net/#Dial> 51for available values (most common are "tcp" and "unix") 52'' ; 53}; 54 55host = lib . mkOption { 56type = with lib . types ; nullOr str ; 57default = null ; 58example = "192.168.1.1" ; 59description = "The address where MPD is listening for connections." ; 60}; 61 62port = lib . mkOption { 63type = with lib . types ; nullOr port ; 64default = null ; 65description = '' 66The port number where MPD is listening for connections. 67'' ; 68}; 69 70password = lib . mkOption { 71type = with lib . types ; nullOr str ; 72default = null ; 73description = '' 74The password to connect to MPD. 75'' ; 76}; 77}; 78}; 79 80config = lib . mkIf cfg . enable { 81assertions = [ 82( lib . hm . assertions . assertPlatform "services.mpd-mpris" pkgs 83lib . platforms . linux ) 84]; 85 86systemd . user . services . mpd-mpris = { 87Install = { WantedBy = [ "default.target" ]; }; 88 89Unit = { 90Description = 91"mpd-mpris: An implementation of the MPRIS protocol for MPD" ; 92After = [ "mpd.service" ]; 93Requires = lib . mkIf cfg . mpd . useLocal [ "mpd.service" ]; 94}; 95 96Service = { 97Type = "simple" ; 98Restart = "on-failure" ; 99RestartSec = "5s" ; 100ExecStart = renderCmd cfg . package { 101no-instance = true ; 102network = ignoreIfLocalMpd cfg . mpd . network ; 103host = ignoreIfLocalMpd cfg . mpd . host ; 104port = ignoreIfLocalMpd cfg . mpd . port ; 105pwd = cfg . mpd . password ; 106}; 107}; 108}; 109}; 110}