2017-06-25 16:43:10 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.minio;
|
2021-06-02 20:34:06 +00:00
|
|
|
|
|
|
|
legacyCredentials = cfg: pkgs.writeText "minio-legacy-credentials" ''
|
|
|
|
MINIO_ROOT_USER=${cfg.accessKey}
|
|
|
|
MINIO_ROOT_PASSWORD=${cfg.secretKey}
|
|
|
|
'';
|
2017-06-25 16:43:10 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
meta.maintainers = [ maintainers.bachp ];
|
|
|
|
|
|
|
|
options.services.minio = {
|
2024-04-13 12:54:15 +00:00
|
|
|
enable = mkEnableOption "Minio Object Storage";
|
2017-06-25 16:43:10 +00:00
|
|
|
|
|
|
|
listenAddress = mkOption {
|
|
|
|
default = ":9000";
|
|
|
|
type = types.str;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "IP address and port of the server.";
|
2021-08-09 20:56:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
consoleAddress = mkOption {
|
|
|
|
default = ":9001";
|
|
|
|
type = types.str;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "IP address and port of the web UI (console).";
|
2017-06-25 16:43:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
dataDir = mkOption {
|
2021-04-10 11:42:47 +00:00
|
|
|
default = [ "/var/lib/minio/data" ];
|
2023-07-03 19:50:56 +00:00
|
|
|
type = types.listOf (types.either types.path types.str);
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "The list of data directories or nodes for storing the objects. Use one path for regular operation and the minimum of 4 endpoints for Erasure Code mode.";
|
2017-06-25 16:43:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
configDir = mkOption {
|
|
|
|
default = "/var/lib/minio/config";
|
|
|
|
type = types.path;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "The config directory, for the access keys and other settings.";
|
2017-06-25 16:43:10 +00:00
|
|
|
};
|
|
|
|
|
2017-07-07 22:11:44 +00:00
|
|
|
accessKey = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.str;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2017-07-07 22:11:44 +00:00
|
|
|
Access key of 5 to 20 characters in length that clients use to access the server.
|
|
|
|
This overrides the access key that is generated by minio on first startup and stored inside the
|
|
|
|
`configDir` directory.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
secretKey = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.str;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2017-07-07 22:11:44 +00:00
|
|
|
Specify the Secret key of 8 to 40 characters in length that clients use to access the server.
|
|
|
|
This overrides the secret key that is generated by minio on first startup and stored inside the
|
|
|
|
`configDir` directory.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-03-13 23:44:29 +00:00
|
|
|
rootCredentialsFile = mkOption {
|
2021-06-02 20:34:06 +00:00
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2021-06-02 20:34:06 +00:00
|
|
|
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";
|
|
|
|
};
|
|
|
|
|
2017-07-07 22:11:44 +00:00
|
|
|
region = mkOption {
|
|
|
|
default = "us-east-1";
|
|
|
|
type = types.str;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2017-07-07 22:11:44 +00:00
|
|
|
The physical location of the server. By default it is set to us-east-1, which is same as AWS S3's and Minio's default region.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
browser = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Enable or disable access to web UI.";
|
2017-07-07 22:11:44 +00:00
|
|
|
};
|
|
|
|
|
2023-11-27 00:19:27 +00:00
|
|
|
package = mkPackageOption pkgs "minio" { };
|
2017-06-25 16:43:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-06-02 20:34:06 +00:00
|
|
|
warnings = optional ((cfg.accessKey != "") || (cfg.secretKey != "")) "services.minio.`accessKey` and services.minio.`secretKey` are deprecated, please use services.minio.`rootCredentialsFile` instead.";
|
|
|
|
|
2023-03-13 23:50:04 +00:00
|
|
|
systemd = lib.mkMerge [{
|
|
|
|
tmpfiles.rules = [
|
|
|
|
"d '${cfg.configDir}' - minio minio - -"
|
2023-07-03 19:50:56 +00:00
|
|
|
] ++ (map (x: "d '" + x + "' - minio minio - - ") (builtins.filter lib.types.path.check cfg.dataDir));
|
2023-03-13 23:50:04 +00:00
|
|
|
|
|
|
|
services.minio = {
|
|
|
|
description = "Minio Object Storage";
|
2023-10-04 05:21:50 +00:00
|
|
|
wants = [ "network-online.target" ];
|
2023-03-13 23:50:04 +00:00
|
|
|
after = [ "network-online.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"}";
|
|
|
|
};
|
2017-06-25 16:43:10 +00:00
|
|
|
};
|
2023-03-13 23:50:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
(lib.mkIf (cfg.rootCredentialsFile != null) {
|
2023-03-16 16:45:09 +00:00
|
|
|
# The service will fail if the credentials file is missing
|
2023-03-13 23:50:04 +00:00
|
|
|
services.minio.unitConfig.ConditionPathExists = cfg.rootCredentialsFile;
|
|
|
|
|
2023-03-16 16:45:09 +00:00
|
|
|
# The service will not restart if the credentials file has
|
|
|
|
# been changed. This can cause stale root credentials.
|
2023-03-13 23:50:04 +00:00
|
|
|
paths.minio-root-credentials = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
pathConfig = {
|
|
|
|
PathChanged = [ cfg.rootCredentialsFile ];
|
|
|
|
Unit = "minio-restart.service";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.minio-restart = {
|
|
|
|
description = "Restart MinIO";
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
systemctl restart minio.service
|
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = 5;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})];
|
2017-06-25 16:43:10 +00:00
|
|
|
|
2018-06-29 23:58:35 +00:00
|
|
|
users.users.minio = {
|
2017-06-25 16:43:10 +00:00
|
|
|
group = "minio";
|
|
|
|
uid = config.ids.uids.minio;
|
|
|
|
};
|
|
|
|
|
2018-06-29 23:58:35 +00:00
|
|
|
users.groups.minio.gid = config.ids.uids.minio;
|
2017-06-25 16:43:10 +00:00
|
|
|
};
|
|
|
|
}
|