1 { config, lib, pkgs, ... }:
6 cfg = config.services.minio;
8 legacyCredentials = cfg: pkgs.writeText "minio-legacy-credentials" ''
9 MINIO_ROOT_USER=${cfg.accessKey}
10 MINIO_ROOT_PASSWORD=${cfg.secretKey}
14 meta.maintainers = [ maintainers.bachp ];
16 options.services.minio = {
17 enable = mkEnableOption "Minio Object Storage";
19 listenAddress = mkOption {
22 description = "IP address and port of the server.";
25 consoleAddress = mkOption {
28 description = "IP address and port of the web UI (console).";
32 default = [ "/var/lib/minio/data" ];
33 type = types.listOf (types.either types.path types.str);
34 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.";
37 configDir = mkOption {
38 default = "/var/lib/minio/config";
40 description = "The config directory, for the access keys and other settings.";
43 accessKey = mkOption {
47 Access key of 5 to 20 characters in length that clients use to access the server.
48 This overrides the access key that is generated by minio on first startup and stored inside the
49 `configDir` directory.
53 secretKey = mkOption {
57 Specify the Secret key of 8 to 40 characters in length that clients use to access the server.
58 This overrides the secret key that is generated by minio on first startup and stored inside the
59 `configDir` directory.
63 rootCredentialsFile = mkOption {
64 type = types.nullOr types.path;
67 File containing the MINIO_ROOT_USER, default is "minioadmin", and
68 MINIO_ROOT_PASSWORD (length >= 8), default is "minioadmin"; in the format of
69 an EnvironmentFile=, as described by systemd.exec(5).
71 example = "/etc/nixos/minio-root-credentials";
75 default = "us-east-1";
78 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.
85 description = "Enable or disable access to web UI.";
88 package = mkPackageOption pkgs "minio" { };
91 config = mkIf cfg.enable {
92 warnings = optional ((cfg.accessKey != "") || (cfg.secretKey != "")) "services.minio.`accessKey` and services.minio.`secretKey` are deprecated, please use services.minio.`rootCredentialsFile` instead.";
94 systemd = lib.mkMerge [{
96 "d '${cfg.configDir}' - minio minio - -"
97 ] ++ (map (x: "d '" + x + "' - minio minio - - ") (builtins.filter lib.types.path.check cfg.dataDir));
100 description = "Minio Object Storage";
101 wants = [ "network-online.target" ];
102 after = [ "network-online.target" ];
103 wantedBy = [ "multi-user.target" ];
105 ExecStart = "${cfg.package}/bin/minio server --json --address ${cfg.listenAddress} --console-address ${cfg.consoleAddress} --config-dir=${cfg.configDir} ${toString cfg.dataDir}";
111 if (cfg.rootCredentialsFile != null) then cfg.rootCredentialsFile
112 else if ((cfg.accessKey != "") || (cfg.secretKey != "")) then (legacyCredentials cfg)
116 MINIO_REGION = "${cfg.region}";
117 MINIO_BROWSER = "${if cfg.browser then "on" else "off"}";
122 (lib.mkIf (cfg.rootCredentialsFile != null) {
123 # The service will fail if the credentials file is missing
124 services.minio.unitConfig.ConditionPathExists = cfg.rootCredentialsFile;
126 # The service will not restart if the credentials file has
127 # been changed. This can cause stale root credentials.
128 paths.minio-root-credentials = {
129 wantedBy = [ "multi-user.target" ];
132 PathChanged = [ cfg.rootCredentialsFile ];
133 Unit = "minio-restart.service";
137 services.minio-restart = {
138 description = "Restart MinIO";
141 systemctl restart minio.service
146 Restart = "on-failure";
152 users.users.minio = {
154 uid = config.ids.uids.minio;
157 users.groups.minio.gid = config.ids.uids.minio;