git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/mpd: Allow to configure a credentialsFile

Allow to specify a password file to be located outside the store, and be read in `ExecStartPre`.

commitccee8dc09f791f363c1e4d2053983434aec54bc6 authorDoron Behar <doron.behar@gmail.com> dateSun 16 Aug 2020, 17:56 (6 years ago) parenta598516
1 file changed+26−1
nixos/modules/services/audio/mpd.nix+26−1
nixos/modules/services/audio/mpd.nix+26−1
@@ -140,6 +140,18 @@ in {
140140 '';
141141 };
142142
143+ credentialsFile = mkOption {
144+ type = types.path;
145+ description = ''
146+ Path to a file to be merged with the settings during the service startup.
147+ Useful to merge a file which is better kept out of the Nix store
148+ because it contains sensible data like MPD's password. Example may look like this:
149+ <literal>password "myMpdPassword@read,add,control,admin"</literal>
150+ '';
151+ default = "/dev/null";
152+ example = "/var/lib/secrets/mpd.conf";
153+ };
154+
143155 fluidsynth = mkOption {
144156 type = types.bool;
145157 default = false;
@@ -181,7 +193,12 @@ in {
181193
182194 serviceConfig = {
183195 User = "${cfg.user}";
184− ExecStart = "${pkgs.mpd}/bin/mpd --no-daemon ${mpdConf}";
196+ ExecStart = "${pkgs.mpd}/bin/mpd --no-daemon /etc/mpd.conf";
197+ ExecStartPre = pkgs.writeScript "mpd-start-pre" ''
198+ #!${pkgs.runtimeShell}
199+ set -euo pipefail
200+ cat ${mpdConf} ${cfg.credentialsFile} > /etc/mpd.conf
201+ '';
185202 Type = "notify";
186203 LimitRTPRIO = 50;
187204 LimitRTTIME = "infinity";
@@ -195,6 +212,14 @@ in {
195212 Restart = "always";
196213 };
197214 };
215+ environment.etc."mpd.conf" = {
216+ mode = "0640";
217+ group = cfg.group;
218+ user = cfg.user;
219+ # To be modified by the service' ExecStartPre
220+ text = ''
221+ '';
222+ };
198223
199224 users.users = optionalAttrs (cfg.user == name) {
200225 ${name} = {