@@ -11,6 +11,10 @@ let
1111 cfg = config.services.mpd;
1212
1313 mpdConf = pkgs.writeText "mpd.conf" ''
14+ # This file was automatically generated by NixOS. Edit mpd's configuration
15+ # via NixOS' configuration.nix, as this file will be rewritten upon mpd's
16+ # restart.
17+
1418 music_directory "${cfg.musicDirectory}"
1519 playlist_directory "${cfg.playlistDirectory}"
1620 ${lib.optionalString (cfg.dbFile != null) ''
@@ -140,6 +144,18 @@ in {
140144 '';
141145 };
142146
147+ credentialsFile = mkOption {
148+ type = types.path;
149+ description = ''
150+ Path to a file to be merged with the settings during the service startup.
151+ Useful to merge a file which is better kept out of the Nix store
152+ because it contains sensible data like MPD's password. Example may look like this:
153+ <literal>password "myMpdPassword@read,add,control,admin"</literal>
154+ '';
155+ default = "/dev/null";
156+ example = "/var/lib/secrets/mpd.conf";
157+ };
158+
143159 fluidsynth = mkOption {
144160 type = types.bool;
145161 default = false;
@@ -181,7 +197,12 @@ in {
181197
182198 serviceConfig = {
183199 User = "${cfg.user}";
184− ExecStart = "${pkgs.mpd}/bin/mpd --no-daemon ${mpdConf}";
200+ ExecStart = "${pkgs.mpd}/bin/mpd --no-daemon /etc/mpd.conf";
201+ ExecStartPre = pkgs.writeScript "mpd-start-pre" ''
202+ #!${pkgs.runtimeShell}
203+ set -euo pipefail
204+ cat ${mpdConf} ${cfg.credentialsFile} > /etc/mpd.conf
205+ '';
185206 Type = "notify";
186207 LimitRTPRIO = 50;
187208 LimitRTTIME = "infinity";
@@ -195,6 +216,14 @@ in {
195216 Restart = "always";
196217 };
197218 };
219+ environment.etc."mpd.conf" = {
220+ mode = "0640";
221+ group = cfg.group;
222+ user = cfg.user;
223+ # To be modified by the service' ExecStartPre
224+ text = ''
225+ '';
226+ };
198227
199228 users.users = optionalAttrs (cfg.user == name) {
200229 ${name} = {