diff --git a/modules/misc/ids.nix b/modules/misc/ids.nix index 8a4175a7bd16..a0ac4dab5b1e 100644 --- a/modules/misc/ids.nix +++ b/modules/misc/ids.nix @@ -68,6 +68,7 @@ in dovenull2 = 47; unbound = 48; prayer = 49; + mpd = 50; # When adding a uid, make sure it doesn't match an existing gid. @@ -116,6 +117,7 @@ in virtuoso = 44; dovecot2 = 45; prayer = 46; + mpd = 47; # When adding a gid, make sure it doesn't match an existing uid. diff --git a/modules/module-list.nix b/modules/module-list.nix index 7230998370c3..ea800648eab3 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -53,6 +53,7 @@ ./services/audio/alsa.nix ./services/audio/fuppes.nix ./services/audio/pulseaudio.nix + ./services/audio/mpd.nix ./services/backup/mysql-backup.nix ./services/backup/postgresql-backup.nix ./services/backup/sitecopy-backup.nix diff --git a/modules/services/audio/mpd.nix b/modules/services/audio/mpd.nix new file mode 100644 index 000000000000..4a7ae355e4c1 --- /dev/null +++ b/modules/services/audio/mpd.nix @@ -0,0 +1,99 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +let + + uid = config.ids.uids.mpd; + gid = config.ids.gids.mpd; + +in + +{ + + ###### interface + + options = { + + services.mpd = { + + enable = mkOption { + default = false; + description = '' + Whether to enable the MPD music player daemon (server). + ''; + }; + + conffile = mkOption { + default = '' + music_directory "${config.services.mpd.dataDir}/music" + playlist_directory "${config.services.mpd.dataDir}/playlists" + db_file "${config.services.mpd.dataDir}/tag_cache" + state_file "${config.services.mpd.dataDir}/state" + sticker_file "${config.services.mpd.dataDir}/sticker.sql" + log_file "/var/log/mpd.log" + pid_file "/var/run/mpd/mpd.pid" + bind_to_address "localhost" + user "mpd" + ''; + description = ''The contents of the MPD configuration file mpd.conf''; + }; + + dataDir = mkOption { + default = "/var/lib/mpd/"; + example = "debug"; + description = '' + The root directory of the MPD data tree. Contains a tag cache, + playlists and a music/ subdirectory that should contain (or + symlink to) your music collection. + ''; + }; + + }; + + }; + + + ###### implementation + + config = mkIf config.services.mpd.enable { + + environment.systemPackages = [ pkgs.mpd ]; + + users.extraUsers = singleton + { name = "mpd"; + group = "mpd"; + extraGroups = [ "audio" ]; + description = "MPD system-wide daemon"; + home = "${config.services.mpd.dataDir}"; + }; + + users.extraGroups = singleton + { name = "mpd"; + inherit gid; + }; + + jobs.mpd = + { description = "MPD system-wide server"; + + startOn = "startup"; + + preStart = + '' + mkdir -p /var/run/mpd && chown mpd /var/run/mpd + test -d ${config.services.mpd.dataDir} || \ + ( mkdir -p --mode 755 ${config.services.mpd.dataDir}/music \ + ${config.services.mpd.dataDir}/playlists && \ + chown -R mpd:mpd ${config.services.mpd.dataDir} ) + ''; + + daemonType = "fork"; + exec = + '' + ${pkgs.mpd}/bin/mpd ${pkgs.writeText "mpd.conf" config.services.mpd.conffile} + ''; + }; + + }; + +}