From aa66c9ad372448277ff113bd78039e6a30034662 Mon Sep 17 00:00:00 2001 From: Pascal Bach Date: Sun, 25 Jun 2017 18:43:10 +0200 Subject: [PATCH] minio service: add inital service features: - change listen port and address - configure config and data directory - basic test to check if minio server starts --- nixos/modules/misc/ids.nix | 2 + nixos/modules/module-list.nix | 1 + nixos/modules/services/web-servers/minio.nix | 69 ++++++++++++++++++++ nixos/tests/minio.nix | 19 ++++++ 4 files changed, 91 insertions(+) create mode 100644 nixos/modules/services/web-servers/minio.nix create mode 100644 nixos/tests/minio.nix diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix index d7459e3fe91..22059bb7fbb 100644 --- a/nixos/modules/misc/ids.nix +++ b/nixos/modules/misc/ids.nix @@ -295,6 +295,7 @@ aria2 = 277; clickhouse = 278; rslsync = 279; + minio = 280; # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399! @@ -559,6 +560,7 @@ aria2 = 277; clickhouse = 278; rslsync = 279; + minio = 280; # When adding a gid, make sure it doesn't match an existing # uid. Users and groups with the same name should have equal diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 07be6555b23..5d9b062f204 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -588,6 +588,7 @@ ./services/web-servers/lighttpd/default.nix ./services/web-servers/lighttpd/gitweb.nix ./services/web-servers/lighttpd/inginious.nix + ./services/web-servers/minio.nix ./services/web-servers/nginx/default.nix ./services/web-servers/phpfpm/default.nix ./services/web-servers/shellinabox.nix diff --git a/nixos/modules/services/web-servers/minio.nix b/nixos/modules/services/web-servers/minio.nix new file mode 100644 index 00000000000..1893edf3a77 --- /dev/null +++ b/nixos/modules/services/web-servers/minio.nix @@ -0,0 +1,69 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.minio; +in +{ + meta.maintainers = [ maintainers.bachp ]; + + options.services.minio = { + enable = mkEnableOption "Minio Object Storage"; + + listenAddress = mkOption { + default = ":9000"; + type = types.str; + description = "Listen on a specific IP address and port."; + }; + + dataDir = mkOption { + default = "/var/lib/minio/data"; + type = types.path; + description = "The data directory, for storing the objects."; + }; + + configDir = mkOption { + default = "/var/lib/minio/config"; + type = types.path; + description = "The config directory, for the access keys and other settings."; + }; + + package = mkOption { + default = pkgs.minio; + defaultText = "pkgs.minio"; + type = types.package; + description = "Minio package to use."; + }; + }; + + config = mkIf cfg.enable { + systemd.services.minio = { + description = "Minio Object Storage"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + preStart = '' + # Make sure directories exist with correct owner + mkdir -p ${cfg.configDir} + chown -R minio:minio ${cfg.configDir} + mkdir -p ${cfg.dataDir} + chown minio:minio ${cfg.dataDir} + ''; + serviceConfig = { + PermissionsStartOnly = true; + ExecStart = "${cfg.package}/bin/minio server --address ${cfg.listenAddress} --config-dir=${cfg.configDir} ${cfg.dataDir}"; + Type = "simple"; + User = "minio"; + Group = "minio"; + LimitNOFILE = 65536; + }; + }; + + users.extraUsers.minio = { + group = "minio"; + uid = config.ids.uids.minio; + }; + + users.extraGroups.minio.gid = config.ids.uids.minio; + }; +} diff --git a/nixos/tests/minio.nix b/nixos/tests/minio.nix new file mode 100644 index 00000000000..462a3bc4768 --- /dev/null +++ b/nixos/tests/minio.nix @@ -0,0 +1,19 @@ +import ./make-test.nix ({ pkgs, ...} : { + name = "minio"; + meta = with pkgs.stdenv.lib.maintainers; { + maintainers = [ bachp ]; + }; + + machine = { config, pkgs, ... }: { + services.minio.enable = true; + }; + + testScript = + '' + startAll; + $machine->waitForUnit("minio.service"); + $machine->waitForOpenPort(9000); + $machine->succeed("curl --fail http://localhost:9000/minio/index.html"); + $machine->shutdown; + ''; +})