mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 21:50:33 +03:00
Merge pull request #107508 from Sohalt/mpd-credentials
This commit is contained in:
commit
70d194c818
1 changed files with 44 additions and 20 deletions
|
@ -10,6 +10,14 @@ let
|
||||||
gid = config.ids.gids.mpd;
|
gid = config.ids.gids.mpd;
|
||||||
cfg = config.services.mpd;
|
cfg = config.services.mpd;
|
||||||
|
|
||||||
|
credentialsPlaceholder = (creds:
|
||||||
|
let
|
||||||
|
placeholders = (imap0
|
||||||
|
(i: c: ''password "{{password-${toString i}}}@${concatStringsSep "," c.permissions}"'')
|
||||||
|
creds);
|
||||||
|
in
|
||||||
|
concatStringsSep "\n" placeholders);
|
||||||
|
|
||||||
mpdConf = pkgs.writeText "mpd.conf" ''
|
mpdConf = pkgs.writeText "mpd.conf" ''
|
||||||
# This file was automatically generated by NixOS. Edit mpd's configuration
|
# This file was automatically generated by NixOS. Edit mpd's configuration
|
||||||
# via NixOS' configuration.nix, as this file will be rewritten upon mpd's
|
# via NixOS' configuration.nix, as this file will be rewritten upon mpd's
|
||||||
|
@ -32,6 +40,8 @@ let
|
||||||
}
|
}
|
||||||
''}
|
''}
|
||||||
|
|
||||||
|
${credentialsPlaceholder cfg.credentials}
|
||||||
|
|
||||||
${cfg.extraConfig}
|
${cfg.extraConfig}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
@ -152,16 +162,35 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
credentialsFile = mkOption {
|
credentials = mkOption {
|
||||||
type = types.path;
|
type = types.listOf (types.submodule {
|
||||||
|
options = {
|
||||||
|
passwordFile = mkOption {
|
||||||
|
type = types.path;
|
||||||
|
description = ''
|
||||||
|
Path to file containing the password.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
permissions = let
|
||||||
|
perms = ["read" "add" "control" "admin"];
|
||||||
|
in mkOption {
|
||||||
|
type = types.listOf (types.enum perms);
|
||||||
|
default = [ "read" ];
|
||||||
|
description = ''
|
||||||
|
List of permissions that are granted with this password.
|
||||||
|
Permissions can be "${concatStringsSep "\", \"" perms}".
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
description = ''
|
description = ''
|
||||||
Path to a file to be merged with the settings during the service startup.
|
Credentials and permissions for accessing the mpd server.
|
||||||
Useful to merge a file which is better kept out of the Nix store
|
|
||||||
because it contains sensible data like MPD's password. Example may look like this:
|
|
||||||
<literal>password "myMpdPassword@read,add,control,admin"</literal>
|
|
||||||
'';
|
'';
|
||||||
default = "/dev/null";
|
default = [];
|
||||||
example = "/var/lib/secrets/mpd.conf";
|
example = [
|
||||||
|
{passwordFile = "/var/lib/secrets/mpd_readonly_password"; permissions = [ "read" ];}
|
||||||
|
{passwordFile = "/var/lib/secrets/mpd_admin_password"; permissions = ["read" "add" "control" "admin"];}
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
fluidsynth = mkOption {
|
fluidsynth = mkOption {
|
||||||
|
@ -201,12 +230,15 @@ in {
|
||||||
serviceConfig = mkMerge [
|
serviceConfig = mkMerge [
|
||||||
{
|
{
|
||||||
User = "${cfg.user}";
|
User = "${cfg.user}";
|
||||||
ExecStart = "${pkgs.mpd}/bin/mpd --no-daemon /etc/mpd.conf";
|
ExecStart = "${pkgs.mpd}/bin/mpd --no-daemon /run/mpd/mpd.conf";
|
||||||
ExecStartPre = pkgs.writeScript "mpd-start-pre" ''
|
ExecStartPre = pkgs.writeShellScript "mpd-start-pre" ''
|
||||||
#!${pkgs.runtimeShell}
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
cat ${mpdConf} ${cfg.credentialsFile} > /etc/mpd.conf
|
install -m 600 ${mpdConf} /run/mpd/mpd.conf
|
||||||
|
${pkgs.replace}/bin/replace-literal -fe ${
|
||||||
|
concatStringsSep " -a " (imap0 (i: c: "\"{{password-${toString i}}}\" \"$(cat ${c.passwordFile})\"") cfg.credentials)
|
||||||
|
} /run/mpd/mpd.conf
|
||||||
'';
|
'';
|
||||||
|
RuntimeDirectory = "mpd";
|
||||||
Type = "notify";
|
Type = "notify";
|
||||||
LimitRTPRIO = 50;
|
LimitRTPRIO = 50;
|
||||||
LimitRTTIME = "infinity";
|
LimitRTTIME = "infinity";
|
||||||
|
@ -230,14 +262,6 @@ in {
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
environment.etc."mpd.conf" = {
|
|
||||||
mode = "0640";
|
|
||||||
group = cfg.group;
|
|
||||||
user = cfg.user;
|
|
||||||
# To be modified by the service' ExecStartPre
|
|
||||||
text = ''
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
users.users = optionalAttrs (cfg.user == name) {
|
users.users = optionalAttrs (cfg.user == name) {
|
||||||
${name} = {
|
${name} = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue