Skip to content

Commit

Permalink
nixos/minio: activate/restart service on credentials path changes
Browse files Browse the repository at this point in the history
Otherwise the `minio.service` service will fail either:

* with a message that the EnvironmentFile does not exist
* or silently with potentially stale credentials
  • Loading branch information
jsoo1 committed Mar 14, 2023
1 parent 8eeb5c3 commit ceb969c
Showing 1 changed file with 52 additions and 23 deletions.
75 changes: 52 additions & 23 deletions nixos/modules/services/web-servers/minio.nix
Original file line number Diff line number Diff line change
Expand Up @@ -96,30 +96,59 @@ 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);

systemd.services.minio = {
description = "Minio Object Storage";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${cfg.package}/bin/minio server --json --address ${cfg.listenAddress} --console-address ${cfg.consoleAddress} --config-dir=${cfg.configDir} ${toString cfg.dataDir}";
Type = "simple";
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;
systemd = lib.mkMerge [{
tmpfiles.rules = [
"d '${cfg.configDir}' - minio minio - -"
] ++ (map (x: "d '" + x + "' - minio minio - - ") cfg.dataDir);

services.minio = {
description = "Minio Object Storage";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${cfg.package}/bin/minio server --json --address ${cfg.listenAddress} --console-address ${cfg.consoleAddress} --config-dir=${cfg.configDir} ${toString cfg.dataDir}";
Type = "simple";
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"}";
};
};
environment = {
MINIO_REGION = "${cfg.region}";
MINIO_BROWSER = "${if cfg.browser then "on" else "off"}";
};
};
}

(lib.mkIf (cfg.rootCredentialsFile != null) {
services.minio.unitConfig.ConditionPathExists = cfg.rootCredentialsFile;

paths.minio-root-credentials = {
wantedBy = [ "multi-user.target" ];

pathConfig = {
PathChanged = [ config.services.minio.rootCredentialsFile ];
Unit = "minio-restart.service";
};
};

services.minio-restart = {
description = "Restart MinIO";

script = ''
systemctl restart minio.service
'';

serviceConfig = {
Type = "oneshot";
Restart = "on-failure";
RestartSec = 5;
};
};
})];

users.users.minio = {
group = "minio";
Expand Down

0 comments on commit ceb969c

Please sign in to comment.