2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2011-12-05 02:51:05 +01:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2011-12-05 02:51:05 +01:00
|
|
|
|
|
|
|
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"
|
2015-04-10 23:10:14 +02:00
|
|
|
db_file "${cfg.dbFile}"
|
2013-01-27 20:21:04 +01:00
|
|
|
state_file "${cfg.dataDir}/state"
|
|
|
|
sticker_file "${cfg.dataDir}/sticker.sql"
|
|
|
|
log_file "syslog"
|
2015-03-08 11:12:20 +01:00
|
|
|
user "${cfg.user}"
|
|
|
|
group "${cfg.group}"
|
2015-03-14 13:08:22 +01:00
|
|
|
|
2015-12-24 00:04:04 +01:00
|
|
|
${optionalString (cfg.network.listenAddress != "any") ''bind_to_address "${cfg.network.listenAddress}"''}
|
2015-03-14 13:08:22 +01:00
|
|
|
${optionalString (cfg.network.port != 6600) ''port "${toString cfg.network.port}"''}
|
|
|
|
|
2013-01-27 20:21:04 +01:00
|
|
|
${cfg.extraConfig}
|
2014-09-15 00:06:57 +02:00
|
|
|
'';
|
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
|
|
|
|
|
2014-09-15 00:06:57 +02:00
|
|
|
options = {
|
2011-12-05 02:51:05 +01:00
|
|
|
|
2014-09-15 00:06:57 +02: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.
|
2014-09-15 00:06:57 +02:00
|
|
|
'';
|
|
|
|
};
|
2013-01-27 20:21:04 +01:00
|
|
|
|
|
|
|
musicDirectory = mkOption {
|
|
|
|
default = "${cfg.dataDir}/music";
|
|
|
|
description = ''
|
2015-03-08 11:12:20 +01:00
|
|
|
The directory where mpd reads music from.
|
2014-09-15 00:06:57 +02:00
|
|
|
'';
|
|
|
|
};
|
2013-01-27 20:21:04 +01:00
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2014-09-15 00:06:57 +02:00
|
|
|
default = "";
|
2013-01-27 20:21:04 +01:00
|
|
|
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.
|
2014-09-15 00:06:57 +02:00
|
|
|
'';
|
|
|
|
};
|
2011-12-05 02:51:05 +01:00
|
|
|
|
|
|
|
dataDir = mkOption {
|
2014-06-17 05:24:39 +02:00
|
|
|
default = "/var/lib/mpd";
|
2011-12-05 02:51:05 +01:00
|
|
|
description = ''
|
2013-01-27 20:21:04 +01:00
|
|
|
The directory where MPD stores its state, tag cache,
|
|
|
|
playlists etc.
|
2014-09-15 00:06:57 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-03-08 11:12:20 +01:00
|
|
|
user = mkOption {
|
|
|
|
default = "mpd";
|
|
|
|
description = "User account under which MPD runs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
default = "mpd";
|
|
|
|
description = "Group account under which MPD runs.";
|
|
|
|
};
|
|
|
|
|
2014-09-15 00:06:57 +02:00
|
|
|
network = {
|
|
|
|
|
2015-12-24 00:04:04 +01:00
|
|
|
listenAddress = mkOption {
|
2014-09-15 00:06:57 +02:00
|
|
|
default = "any";
|
|
|
|
description = ''
|
|
|
|
This setting sets the address for the daemon to listen on. Careful attention
|
|
|
|
should be paid if this is assigned to anything other then the default, any.
|
|
|
|
This setting can deny access to control of the daemon.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
default = 6600;
|
|
|
|
description = ''
|
|
|
|
This setting is the TCP port that is desired for the daemon to get assigned
|
|
|
|
to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
2015-04-10 23:10:14 +02:00
|
|
|
|
|
|
|
dbFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "${cfg.dataDir}/tag_cache";
|
|
|
|
description = ''
|
|
|
|
The path to MPD's database.
|
|
|
|
'';
|
|
|
|
};
|
2014-09-15 00:06:57 +02:00
|
|
|
};
|
2011-12-05 02:51:05 +01:00
|
|
|
|
2014-09-15 00:06:57 +02: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 ];
|
2015-03-08 11:12:20 +01:00
|
|
|
preStart = "mkdir -p ${cfg.dataDir} && chown -R ${cfg.user}:${cfg.group} ${cfg.dataDir}";
|
2013-02-28 19:26:19 +01:00
|
|
|
script = "exec mpd --no-daemon ${mpdConf}";
|
2014-12-22 12:20:19 +01:00
|
|
|
serviceConfig = {
|
2015-06-13 23:24:19 +02:00
|
|
|
User = "${cfg.user}";
|
2015-02-10 10:18:54 +01:00
|
|
|
PermissionsStartOnly = true;
|
2014-12-22 12:20:19 +01:00
|
|
|
};
|
2013-01-27 20:21:04 +01:00
|
|
|
};
|
|
|
|
|
2015-03-08 11:12:20 +01:00
|
|
|
users.extraUsers = optionalAttrs (cfg.user == "mpd") (singleton {
|
2013-01-27 20:21:04 +01:00
|
|
|
inherit uid;
|
2015-03-08 11:12:20 +01:00
|
|
|
name = "mpd";
|
|
|
|
group = cfg.group;
|
2013-01-27 20:21:04 +01:00
|
|
|
extraGroups = [ "audio" ];
|
|
|
|
description = "Music Player Daemon user";
|
|
|
|
home = "${cfg.dataDir}";
|
2015-03-08 11:12:20 +01:00
|
|
|
});
|
2011-12-05 02:51:05 +01:00
|
|
|
|
2015-03-08 11:12:20 +01:00
|
|
|
users.extraGroups = optionalAttrs (cfg.group == "mpd") (singleton {
|
2015-03-20 20:58:13 +01:00
|
|
|
name = "mpd";
|
2015-03-08 11:12:20 +01:00
|
|
|
gid = gid;
|
|
|
|
});
|
2011-12-05 02:51:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|