nixos/minio: credentialfile

This commit is contained in:
Pascal Bach 2021-06-02 22:34:06 +02:00
parent 9cd41d69a1
commit b1b9e003dc

View File

@ -4,6 +4,11 @@ with lib;
let
cfg = config.services.minio;
legacyCredentials = cfg: pkgs.writeText "minio-legacy-credentials" ''
MINIO_ROOT_USER=${cfg.accessKey}
MINIO_ROOT_PASSWORD=${cfg.secretKey}
'';
in
{
meta.maintainers = [ maintainers.bachp ];
@ -49,6 +54,17 @@ in
'';
};
rootCredentialsFile = mkOption {
type = types.nullOr types.path;
default = null;
description = ''
File containing the MINIO_ROOT_USER, default is "minioadmin", and
MINIO_ROOT_PASSWORD (length >= 8), default is "minioadmin"; in the format of
an EnvironmentFile=, as described by systemd.exec(5).
'';
example = "/etc/nixos/minio-root-credentials";
};
region = mkOption {
default = "us-east-1";
type = types.str;
@ -72,6 +88,8 @@ in
};
config = mkIf cfg.enable {
warnings = optional ((cfg.accessKey != "") || (cfg.secretKey != "")) "services.minio.`accessKey` and services.minio.`secretKey` are deprecated, please use services.minio.`rootCredentialsFile` instead.";
systemd.tmpfiles.rules = [
"d '${cfg.configDir}' - minio minio - -"
] ++ (map (x: "d '" + x + "' - minio minio - - ") cfg.dataDir);
@ -86,14 +104,13 @@ in
User = "minio";
Group = "minio";
LimitNOFILE = 65536;
EnvironmentFile = if (cfg.rootCredentialsFile != null) then cfg.rootCredentialsFile
else if ((cfg.accessKey != "") || (cfg.secretKey != "")) then (legacyCredentials cfg)
else null;
};
environment = {
MINIO_REGION = "${cfg.region}";
MINIO_BROWSER = "${if cfg.browser then "on" else "off"}";
} // optionalAttrs (cfg.accessKey != "") {
MINIO_ACCESS_KEY = "${cfg.accessKey}";
} // optionalAttrs (cfg.secretKey != "") {
MINIO_SECRET_KEY = "${cfg.secretKey}";
};
};