2011-12-05 02:51:05 +01:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
uid = config.ids.uids.mpd;
|
|
|
|
gid = config.ids.gids.mpd;
|
2013-01-27 20:21:04 +01:00
|
|
|
cfg = config.services.mpd;
|
2011-12-05 02:51:05 +01:00
|
|
|
|
2013-01-27 20:21:04 +01: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 02:51:05 +01:00
|
|
|
|
2013-01-27 20:21:04 +01:00
|
|
|
in {
|
2011-12-05 02:51:05 +01:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
2013-01-27 20:21:04 +01:00
|
|
|
options = {
|
2011-12-05 02:51:05 +01:00
|
|
|
|
2013-01-27 20:21:04 +01:00
|
|
|
services.mpd = {
|
2011-12-05 02:51:05 +01:00
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2013-01-27 20:21:04 +01: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 02:51:05 +01:00
|
|
|
|
|
|
|
dataDir = mkOption {
|
|
|
|
default = "/var/lib/mpd/";
|
|
|
|
description = ''
|
2013-01-27 20:21:04 +01:00
|
|
|
The directory where MPD stores its state, tag cache,
|
|
|
|
playlists etc.
|
|
|
|
'';
|
|
|
|
};
|
2011-12-05 02:51:05 +01:00
|
|
|
|
2013-01-27 20:21:04 +01:00
|
|
|
};
|
2011-12-05 02:51:05 +01:00
|
|
|
|
2013-01-27 20:21:04 +01:00
|
|
|
};
|
2011-12-05 02:51:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2013-01-27 20:21:04 +01:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
systemd.services.mpd = {
|
|
|
|
after = [ "network.target" "sound.target" ];
|
|
|
|
description = "Music Player Daemon";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = [ pkgs.mpd ];
|
|
|
|
script = "mpd --no-daemon ${mpdConf}";
|
|
|
|
};
|
|
|
|
|
|
|
|
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 02:51:05 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|