fork/home-manager
git clone https://git.julia.blue/fork/home-manager
9042c756
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . services . mpdris2 ; 8 9toIni = generators . toINI { 10mkKeyValue = key :value : 11let 12value' = if isBool value then 13( if value then "True" else "False" ) 14else 15toString value ; 16in " ${ key } = ${ value' } " ; 17}; 18 19mpdris2Conf = { 20Connection = { 21host = cfg . mpd . host ; 22port = cfg . mpd . port ; 23music_dir = cfg . mpd . musicDirectory ; 24} // optionalAttrs ( cfg . mpd . password != null ) { 25password = cfg . mpd . password ; 26}; 27 28Bling = { 29notify = cfg . notifications ; 30mmkeys = cfg . multimediaKeys ; 31}; 32}; 33 34in { 35meta . maintainers = [ maintainers . pjones ]; 36 37options . services . mpdris2 = { 38enable = mkEnableOption "mpDris2 the MPD to MPRIS2 bridge" ; 39notifications = mkEnableOption "song change notifications" ; 40multimediaKeys = mkEnableOption "multimedia key support" ; 41 42package = mkOption { 43type = types . package ; 44default = pkgs . mpdris2 ; 45defaultText = literalExpression "pkgs.mpdris2" ; 46description = "The mpDris2 package to use." ; 47}; 48 49mpd = { 50host = mkOption { 51type = types . str ; 52default = config . services . mpd . network . listenAddress ; 53defaultText = "config.services.mpd.network.listenAddress" ; 54example = "192.168.1.1" ; 55description = "The address where MPD is listening for connections." ; 56}; 57 58port = mkOption { 59type = types . port ; 60default = config . services . mpd . network . port ; 61defaultText = "config.services.mpd.network.port" ; 62description = '' 63The port number where MPD is listening for connections. 64'' ; 65}; 66 67musicDirectory = mkOption { 68type = types . nullOr types . path ; 69default = config . services . mpd . musicDirectory ; 70defaultText = "config.services.mpd.musicDirectory" ; 71description = '' 72If set, mpDris2 will use this directory to access music artwork. 73'' ; 74}; 75 76password = mkOption { 77type = types . nullOr types . str ; 78default = null ; 79description = '' 80The password to connect to MPD. 81'' ; 82}; 83}; 84}; 85 86config = mkIf cfg . enable { 87assertions = [ 88( lib . hm . assertions . assertPlatform "services.mpdris2" pkgs 89lib . platforms . linux ) 90]; 91 92xdg . configFile . "mpDris2/mpDris2.conf" . text = toIni mpdris2Conf ; 93 94systemd . user . services . mpdris2 = { 95Install = { WantedBy = [ "default.target" ]; }; 96 97Unit = { 98Description = "MPRIS 2 support for MPD" ; 99After = [ "mpd.service" ]; 100}; 101 102Service = { 103Type = "simple" ; 104Restart = "on-failure" ; 105RestartSec = "5s" ; 106ExecStart = " ${ cfg . package } /bin/mpDris2" ; 107BusName = "org.mpris.MediaPlayer2.mpd" ; 108}; 109}; 110}; 111}