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 (lib.mdDoc "Minio Object Storage");
19 listenAddress = mkOption {
22 description = lib.mdDoc "IP address and port of the server.";
25 consoleAddress = mkOption {
28 description = lib.mdDoc "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 = lib.mdDoc "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 = lib.mdDoc "The config directory, for the access keys and other settings.";
43 accessKey = mkOption {
46 description = lib.mdDoc ''
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 {
56 description = lib.mdDoc ''
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;
66 description = lib.mdDoc ''
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";
77 description = lib.mdDoc ''
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 = lib.mdDoc "Enable or disable access to web UI.";
90 defaultText = literalExpression "pkgs.minio";
92 description = lib.mdDoc "Minio package to use.";
96 config = mkIf cfg.enable {
97 warnings = optional ((cfg.accessKey != "") || (cfg.secretKey != "")) "services.minio.`accessKey` and services.minio.`secretKey` are deprecated, please use services.minio.`rootCredentialsFile` instead.";
99 systemd = lib.mkMerge [{
101 "d '${cfg.configDir}' - minio minio - -"
102 ] ++ (map (x: "d '" + x + "' - minio minio - - ") (builtins.filter lib.types.path.check cfg.dataDir));
105 description = "Minio Object Storage";
106 after = [ "network-online.target" ];
107 wantedBy = [ "multi-user.target" ];
109 ExecStart = "${cfg.package}/bin/minio server --json --address ${cfg.listenAddress} --console-address ${cfg.consoleAddress} --config-dir=${cfg.configDir} ${toString cfg.dataDir}";
115 if (cfg.rootCredentialsFile != null) then cfg.rootCredentialsFile
116 else if ((cfg.accessKey != "") || (cfg.secretKey != "")) then (legacyCredentials cfg)
120 MINIO_REGION = "${cfg.region}";
121 MINIO_BROWSER = "${if cfg.browser then "on" else "off"}";
126 (lib.mkIf (cfg.rootCredentialsFile != null) {
127 # The service will fail if the credentials file is missing
128 services.minio.unitConfig.ConditionPathExists = cfg.rootCredentialsFile;
130 # The service will not restart if the credentials file has
131 # been changed. This can cause stale root credentials.
132 paths.minio-root-credentials = {
133 wantedBy = [ "multi-user.target" ];
136 PathChanged = [ cfg.rootCredentialsFile ];
137 Unit = "minio-restart.service";
141 services.minio-restart = {
142 description = "Restart MinIO";
145 systemctl restart minio.service
150 Restart = "on-failure";
156 users.users.minio = {
158 uid = config.ids.uids.minio;
161 users.groups.minio.gid = config.ids.uids.minio;