diff --git a/nixos/modules/services/audio/mpd.nix b/nixos/modules/services/audio/mpd.nix index b79052337597..9abfb41087b7 100644 --- a/nixos/modules/services/audio/mpd.nix +++ b/nixos/modules/services/audio/mpd.nix @@ -15,6 +15,8 @@ let state_file "${cfg.dataDir}/state" sticker_file "${cfg.dataDir}/sticker.sql" log_file "syslog" + user "${cfg.user}" + group "${cfg.group}" ${if cfg.network.host != "any" then "bind_to_address ${cfg.network.host}" else ""} ${if cfg.network.port != 6600 then @@ -40,8 +42,7 @@ in { musicDirectory = mkOption { default = "${cfg.dataDir}/music"; description = '' - Extra configuration added to the end of MPD's - configuration file, mpd.conf. + The directory where mpd reads music from. ''; }; @@ -62,6 +63,16 @@ in { ''; }; + user = mkOption { + default = "mpd"; + description = "User account under which MPD runs."; + }; + + group = mkOption { + default = "mpd"; + description = "Group account under which MPD runs."; + }; + network = { host = mkOption { @@ -96,7 +107,7 @@ in { description = "Music Player Daemon"; wantedBy = [ "multi-user.target" ]; path = [ pkgs.mpd ]; - preStart = "mkdir -p ${cfg.dataDir} && chown -R mpd:mpd ${cfg.dataDir}"; + preStart = "mkdir -p ${cfg.dataDir} && chown -R ${cfg.user}:${cfg.group} ${cfg.dataDir}"; script = "exec mpd --no-daemon ${mpdConf}"; serviceConfig = { User = "mpd"; @@ -104,16 +115,18 @@ in { }; }; - users.extraUsers.mpd = { + users.extraUsers = optionalAttrs (cfg.user == "mpd") (singleton { inherit uid; - group = "mpd"; + name = "mpd"; + group = cfg.group; extraGroups = [ "audio" ]; description = "Music Player Daemon user"; home = "${cfg.dataDir}"; - }; - - users.extraGroups.mpd.gid = gid; + }); + users.extraGroups = optionalAttrs (cfg.group == "mpd") (singleton { + gid = gid; + }); }; }