Add mpd module

There is room for improvement here. The options in conffile could be broken out into individual options and an extraConfig option added. But I think this looks right.
Patch by mornfall, slightly modified by me

svn path=/nixos/trunk/; revision=30731
This commit is contained in:
Shea Levy 2011-12-05 01:51:05 +00:00
parent 508fea8dac
commit 868c60c92b
3 changed files with 102 additions and 0 deletions

View File

@ -68,6 +68,7 @@ in
dovenull2 = 47; dovenull2 = 47;
unbound = 48; unbound = 48;
prayer = 49; prayer = 49;
mpd = 50;
# When adding a uid, make sure it doesn't match an existing gid. # When adding a uid, make sure it doesn't match an existing gid.
@ -116,6 +117,7 @@ in
virtuoso = 44; virtuoso = 44;
dovecot2 = 45; dovecot2 = 45;
prayer = 46; prayer = 46;
mpd = 47;
# When adding a gid, make sure it doesn't match an existing uid. # When adding a gid, make sure it doesn't match an existing uid.

View File

@ -53,6 +53,7 @@
./services/audio/alsa.nix ./services/audio/alsa.nix
./services/audio/fuppes.nix ./services/audio/fuppes.nix
./services/audio/pulseaudio.nix ./services/audio/pulseaudio.nix
./services/audio/mpd.nix
./services/backup/mysql-backup.nix ./services/backup/mysql-backup.nix
./services/backup/postgresql-backup.nix ./services/backup/postgresql-backup.nix
./services/backup/sitecopy-backup.nix ./services/backup/sitecopy-backup.nix

View File

@ -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}
'';
};
};
}