2011-12-05 01:51:05 +00:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
uid = config.ids.uids.mpd;
|
|
|
|
gid = config.ids.gids.mpd;
|
2013-01-27 19:21:04 +00:00
|
|
|
cfg = config.services.mpd;
|
2011-12-05 01:51:05 +00:00
|
|
|
|
2013-01-27 19:21:04 +00:00
|
|
|
mpdConf = pkgs.writeText "mpd.conf" ''
|
|
|
|
music_directory "${cfg.musicDirectory}"
|
|
|
|
playlist_directory "${cfg.dataDir}/playlists"
|
|
|
|
db_file "${cfg.dataDir}/tag_cache"
|
|
|
|
state_file "${cfg.dataDir}/state"
|
|
|
|
sticker_file "${cfg.dataDir}/sticker.sql"
|
|
|
|
log_file "syslog"
|
|
|
|
user "mpd"
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
2011-12-05 01:51:05 +00:00
|
|
|
|
2013-01-27 19:21:04 +00:00
|
|
|
in {
|
2011-12-05 01:51:05 +00:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
2013-01-27 19:21:04 +00:00
|
|
|
options = {
|
2011-12-05 01:51:05 +00:00
|
|
|
|
2013-01-27 19:21:04 +00:00
|
|
|
services.mpd = {
|
2011-12-05 01:51:05 +00:00
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2013-01-27 19:21:04 +00:00
|
|
|
Whether to enable MPD, the music player daemon.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
musicDirectory = mkOption {
|
|
|
|
default = "${cfg.dataDir}/music";
|
|
|
|
description = ''
|
|
|
|
Extra configuration added to the end of MPD's
|
|
|
|
configuration file, mpd.conf.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Extra directives added to to the end of MPD's configuration file,
|
|
|
|
mpd.conf. Basic configuration like file location and uid/gid
|
|
|
|
is added automatically to the beginning of the file.
|
|
|
|
'';
|
|
|
|
};
|
2011-12-05 01:51:05 +00:00
|
|
|
|
|
|
|
dataDir = mkOption {
|
|
|
|
default = "/var/lib/mpd/";
|
|
|
|
description = ''
|
2013-01-27 19:21:04 +00:00
|
|
|
The directory where MPD stores its state, tag cache,
|
|
|
|
playlists etc.
|
|
|
|
'';
|
|
|
|
};
|
2011-12-05 01:51:05 +00:00
|
|
|
|
2013-01-27 19:21:04 +00:00
|
|
|
};
|
2011-12-05 01:51:05 +00:00
|
|
|
|
2013-01-27 19:21:04 +00:00
|
|
|
};
|
2011-12-05 01:51:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2013-01-27 19:21:04 +00:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
systemd.services.mpd = {
|
|
|
|
after = [ "network.target" "sound.target" ];
|
|
|
|
description = "Music Player Daemon";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = [ pkgs.mpd ];
|
2013-02-21 22:05:40 +00:00
|
|
|
preStart = "mkdir -p ${cfg.dataDir} && chown -R mpd:mpd ${cfg.dataDir}";
|
2013-02-28 18:26:19 +00:00
|
|
|
script = "exec mpd --no-daemon ${mpdConf}";
|
2013-01-27 19:21:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
users.extraUsers.mpd = {
|
|
|
|
inherit uid;
|
|
|
|
group = "mpd";
|
|
|
|
extraGroups = [ "audio" ];
|
|
|
|
description = "Music Player Daemon user";
|
|
|
|
home = "${cfg.dataDir}";
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraGroups.mpd.gid = gid;
|
2011-12-05 01:51:05 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|