mirror of
https://github.com/SebastianWendel/nixpkgs.git
synced 2024-09-20 04:19:00 +02:00
nixos/mpd: conditionally provision required directories with StateDirectory
This commit is contained in:
parent
09e349206d
commit
77a8496907
|
@ -66,7 +66,10 @@ in {
|
||||||
default = "${cfg.dataDir}/music";
|
default = "${cfg.dataDir}/music";
|
||||||
defaultText = ''''${dataDir}/music'';
|
defaultText = ''''${dataDir}/music'';
|
||||||
description = ''
|
description = ''
|
||||||
The directory or NFS/SMB network share where mpd reads music from.
|
The directory or NFS/SMB network share where MPD reads music from. If left
|
||||||
|
as the default value this directory will automatically be created before
|
||||||
|
the MPD server starts, otherwise the sysadmin is responsible for ensuring
|
||||||
|
the directory exists with appropriate ownership and permissions.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -75,7 +78,10 @@ in {
|
||||||
default = "${cfg.dataDir}/playlists";
|
default = "${cfg.dataDir}/playlists";
|
||||||
defaultText = ''''${dataDir}/playlists'';
|
defaultText = ''''${dataDir}/playlists'';
|
||||||
description = ''
|
description = ''
|
||||||
The directory where mpd stores playlists.
|
The directory where MPD stores playlists. If left as the default value
|
||||||
|
this directory will automatically be created before the MPD server starts,
|
||||||
|
otherwise the sysadmin is responsible for ensuring the directory exists
|
||||||
|
with appropriate ownership and permissions.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -94,8 +100,10 @@ in {
|
||||||
type = types.path;
|
type = types.path;
|
||||||
default = "/var/lib/${name}";
|
default = "/var/lib/${name}";
|
||||||
description = ''
|
description = ''
|
||||||
The directory where MPD stores its state, tag cache,
|
The directory where MPD stores its state, tag cache, playlists etc. If
|
||||||
playlists etc.
|
left as the default value this directory will automatically be created
|
||||||
|
before the MPD server starts, otherwise the sysadmin is responsible for
|
||||||
|
ensuring the directory exists with appropriate ownership and permissions.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -185,36 +193,42 @@ in {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.tmpfiles.rules = [
|
|
||||||
"d '${cfg.dataDir}' - ${cfg.user} ${cfg.group} - -"
|
|
||||||
"d '${cfg.playlistDirectory}' - ${cfg.user} ${cfg.group} - -"
|
|
||||||
];
|
|
||||||
|
|
||||||
systemd.services.mpd = {
|
systemd.services.mpd = {
|
||||||
after = [ "network.target" "sound.target" ];
|
after = [ "network.target" "sound.target" ];
|
||||||
description = "Music Player Daemon";
|
description = "Music Player Daemon";
|
||||||
wantedBy = optional (!cfg.startWhenNeeded) "multi-user.target";
|
wantedBy = optional (!cfg.startWhenNeeded) "multi-user.target";
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = mkMerge [
|
||||||
User = "${cfg.user}";
|
{
|
||||||
ExecStart = "${pkgs.mpd}/bin/mpd --no-daemon /etc/mpd.conf";
|
User = "${cfg.user}";
|
||||||
ExecStartPre = pkgs.writeScript "mpd-start-pre" ''
|
ExecStart = "${pkgs.mpd}/bin/mpd --no-daemon /etc/mpd.conf";
|
||||||
#!${pkgs.runtimeShell}
|
ExecStartPre = pkgs.writeScript "mpd-start-pre" ''
|
||||||
set -euo pipefail
|
#!${pkgs.runtimeShell}
|
||||||
cat ${mpdConf} ${cfg.credentialsFile} > /etc/mpd.conf
|
set -euo pipefail
|
||||||
'';
|
cat ${mpdConf} ${cfg.credentialsFile} > /etc/mpd.conf
|
||||||
Type = "notify";
|
'';
|
||||||
LimitRTPRIO = 50;
|
Type = "notify";
|
||||||
LimitRTTIME = "infinity";
|
LimitRTPRIO = 50;
|
||||||
ProtectSystem = true;
|
LimitRTTIME = "infinity";
|
||||||
NoNewPrivileges = true;
|
ProtectSystem = true;
|
||||||
ProtectKernelTunables = true;
|
NoNewPrivileges = true;
|
||||||
ProtectControlGroups = true;
|
ProtectKernelTunables = true;
|
||||||
ProtectKernelModules = true;
|
ProtectControlGroups = true;
|
||||||
RestrictAddressFamilies = "AF_INET AF_INET6 AF_UNIX AF_NETLINK";
|
ProtectKernelModules = true;
|
||||||
RestrictNamespaces = true;
|
RestrictAddressFamilies = "AF_INET AF_INET6 AF_UNIX AF_NETLINK";
|
||||||
Restart = "always";
|
RestrictNamespaces = true;
|
||||||
};
|
Restart = "always";
|
||||||
|
}
|
||||||
|
(mkIf (cfg.dataDir == "/var/lib/${name}") {
|
||||||
|
StateDirectory = [ name ];
|
||||||
|
})
|
||||||
|
(mkIf (cfg.playlistDirectory == "/var/lib/${name}/playlists") {
|
||||||
|
StateDirectory = [ name "${name}/playlists" ];
|
||||||
|
})
|
||||||
|
(mkIf (cfg.musicDirectory == "/var/lib/${name}/music") {
|
||||||
|
StateDirectory = [ name "${name}/music" ];
|
||||||
|
})
|
||||||
|
];
|
||||||
};
|
};
|
||||||
environment.etc."mpd.conf" = {
|
environment.etc."mpd.conf" = {
|
||||||
mode = "0640";
|
mode = "0640";
|
||||||
|
|
|
@ -27,10 +27,12 @@ import ./make-test-python.nix ({ pkgs, lib, ... }:
|
||||||
after = [ "mpd.service" ];
|
after = [ "mpd.service" ];
|
||||||
wantedBy = [ "default.target" ];
|
wantedBy = [ "default.target" ];
|
||||||
script = ''
|
script = ''
|
||||||
mkdir -p ${musicDirectory} && chown -R ${user}:${group} ${musicDirectory}
|
|
||||||
cp ${track} ${musicDirectory}
|
cp ${track} ${musicDirectory}
|
||||||
chown ${user}:${group} ${musicDirectory}/$(basename ${track})
|
|
||||||
'';
|
'';
|
||||||
|
serviceConfig = {
|
||||||
|
User = user;
|
||||||
|
Group = group;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
mkServer = { mpd, musicService, }:
|
mkServer = { mpd, musicService, }:
|
||||||
|
|
Loading…
Reference in a new issue