2025-06-12 18:17:16 -05:00
|
|
|
{
|
|
|
|
|
description = "minio service for storing images with api access";
|
|
|
|
|
|
|
|
|
|
inputs = {
|
|
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
outputs = { self, nixpkgs, ... }: {
|
|
|
|
|
nixosModules.minio-service = { config, lib, pkgs, ... }:
|
|
|
|
|
let
|
|
|
|
|
opts = config.services.minio-service;
|
|
|
|
|
in {
|
|
|
|
|
options.services.minio-service = {
|
|
|
|
|
enable = lib.mkEnableOption "MinIO object storage server";
|
|
|
|
|
|
|
|
|
|
dataDir = lib.mkOption {
|
|
|
|
|
type = lib.types.path;
|
|
|
|
|
default = "/var/lib/minio";
|
|
|
|
|
description = "Directory to store MinIO data.";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
dataPort = lib.mkOption {
|
|
|
|
|
type = lib.types.port;
|
|
|
|
|
default = 9000;
|
|
|
|
|
description = "MinIO S3 API port.";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
consolePort = lib.mkOption {
|
|
|
|
|
type = lib.types.port;
|
|
|
|
|
default = 9001;
|
|
|
|
|
description = "MinIO Admin Console port.";
|
|
|
|
|
};
|
|
|
|
|
|
2025-06-12 19:01:51 -05:00
|
|
|
credentialsFile = lib.mkOption {
|
2025-06-12 18:17:16 -05:00
|
|
|
type = lib.types.path;
|
2025-06-12 19:01:51 -05:00
|
|
|
description = "File containing MinIO credentials.";
|
2025-06-12 18:17:16 -05:00
|
|
|
};
|
|
|
|
|
|
2025-08-16 21:11:24 -05:00
|
|
|
bootstrap-minio = {
|
|
|
|
|
enable = lib.mkEnableOption "Enable bootstrapping minio creds";
|
|
|
|
|
environments = lib.mkOption {
|
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
|
default = [];
|
|
|
|
|
description = "list of environments to bootstrap (dev, prod, stage, etc)";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2025-06-12 18:17:16 -05:00
|
|
|
default-nginx = {
|
|
|
|
|
enable = lib.mkEnableOption "Enable nginx reverse proxy for MinIO";
|
|
|
|
|
hostname = lib.mkOption {
|
2025-08-16 21:15:20 -05:00
|
|
|
type = lib.types.listOf lib.types.str;
|
2025-06-12 18:17:16 -05:00
|
|
|
default = "localhost";
|
|
|
|
|
description = "Hostname for nginx reverse proxy.";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = lib.mkIf opts.enable {
|
|
|
|
|
users.groups.minio = {};
|
|
|
|
|
users.users.minio = {
|
|
|
|
|
isSystemUser = true;
|
2025-06-12 22:15:29 -05:00
|
|
|
createHome = true;
|
2025-06-12 19:32:34 -05:00
|
|
|
home = "${opts.dataDir}";
|
2025-06-12 22:15:29 -05:00
|
|
|
group = "minio";
|
2025-06-12 18:17:16 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.services.minio = {
|
|
|
|
|
description = "MinIO S3-compatible object storage";
|
|
|
|
|
after = [ "network.target" ];
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
|
|
serviceConfig = {
|
2025-06-20 23:54:53 -05:00
|
|
|
ExecStart = ''
|
2025-06-12 18:17:16 -05:00
|
|
|
${pkgs.minio}/bin/minio server ${opts.dataDir} \
|
|
|
|
|
--address ":${toString opts.dataPort}" \
|
|
|
|
|
--console-address ":${toString opts.consolePort}"
|
2025-06-20 22:29:38 -05:00
|
|
|
'';
|
|
|
|
|
|
2025-06-20 23:54:53 -05:00
|
|
|
User = "minio";
|
|
|
|
|
Group = "minio";
|
|
|
|
|
EnvironmentFile = "${opts.credentialsFile}";
|
|
|
|
|
Restart = "always";
|
2025-06-12 18:17:16 -05:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-16 21:11:24 -05:00
|
|
|
systemd.services.bootstrap-minio = lib.mkIf opts.bootstrap-minio.enable {
|
|
|
|
|
description = "Minio bootstrap users, policies, buckets";
|
|
|
|
|
after = [ "minio.service" ];
|
|
|
|
|
requires = [ "minio.service" ];
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
Type = "oneshot";
|
|
|
|
|
ExecStart = pkgs.writeShellScript "bootstrap-minio" ''
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
|
|
echo $SHELL
|
|
|
|
|
'';
|
|
|
|
|
User = "minio";
|
|
|
|
|
Group = "minio";
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2025-06-12 18:17:16 -05:00
|
|
|
services.nginx = lib.mkIf opts.default-nginx.enable {
|
|
|
|
|
enable = true;
|
|
|
|
|
virtualHosts.${opts.default-nginx.hostname} = {
|
|
|
|
|
forceSSL = true;
|
|
|
|
|
enableACME = true;
|
2025-06-12 22:29:53 -05:00
|
|
|
acmeRoot = null;
|
2025-07-02 17:23:37 -05:00
|
|
|
# Dev and Prod buckets must be created manually
|
|
|
|
|
# will work on script/minio command line for this later
|
2025-07-02 17:07:20 -05:00
|
|
|
locations."/console" = {
|
|
|
|
|
proxyPass = "http://localhost:${toString opts.consolePort}/browser";
|
2025-06-12 18:17:16 -05:00
|
|
|
};
|
2025-07-03 10:43:54 -05:00
|
|
|
# Add directive for s3like queries, which only accept root path allegedly
|
2025-07-03 10:44:54 -05:00
|
|
|
locations."/" = {
|
2025-07-03 10:43:54 -05:00
|
|
|
proxyPass = "http://localhost:${toString opts.dataPort}";
|
2025-07-03 15:36:34 -05:00
|
|
|
extraConfig = ''
|
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
|
client_max_body_size 0;
|
|
|
|
|
proxy_buffering off;
|
|
|
|
|
'';
|
2025-07-03 10:43:54 -05:00
|
|
|
};
|
2025-06-12 18:17:16 -05:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = lib.mkMerge [
|
2025-06-12 22:29:53 -05:00
|
|
|
(lib.mkIf opts.enable [ opts.dataPort opts.consolePort ])
|
2025-06-12 18:17:16 -05:00
|
|
|
(lib.mkIf opts.default-nginx.enable [ 80 443 ])
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|
2025-07-02 17:07:20 -05:00
|
|
|
|