2022-10-30 15:09:59 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.garage;
|
2023-10-19 13:55:26 +00:00
|
|
|
toml = pkgs.formats.toml { };
|
2022-10-30 15:09:59 +00:00
|
|
|
configFile = toml.generate "garage.toml" cfg.settings;
|
|
|
|
in
|
|
|
|
{
|
2023-01-11 07:51:40 +00:00
|
|
|
meta = {
|
2023-02-02 18:25:31 +00:00
|
|
|
doc = ./garage.md;
|
2023-01-11 07:51:40 +00:00
|
|
|
maintainers = with pkgs.lib.maintainers; [ raitobezarius ];
|
|
|
|
};
|
2022-10-30 15:09:59 +00:00
|
|
|
|
|
|
|
options.services.garage = {
|
|
|
|
enable = mkEnableOption (lib.mdDoc "Garage Object Storage (S3 compatible)");
|
|
|
|
|
|
|
|
extraEnvironment = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
description = lib.mdDoc "Extra environment variables to pass to the Garage server.";
|
2023-10-19 13:55:26 +00:00
|
|
|
default = { };
|
|
|
|
example = { RUST_BACKTRACE = "yes"; };
|
2022-10-30 15:09:59 +00:00
|
|
|
};
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
environmentFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
description = lib.mdDoc "File containing environment variables to be passed to the Garage server.";
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
2022-10-30 15:09:59 +00:00
|
|
|
logLevel = mkOption {
|
2024-02-29 20:09:43 +00:00
|
|
|
type = types.enum ([ "error" "warn" "info" "debug" "trace" ]);
|
2022-10-30 15:09:59 +00:00
|
|
|
default = "info";
|
|
|
|
example = "debug";
|
|
|
|
description = lib.mdDoc "Garage log level, see <https://garagehq.deuxfleurs.fr/documentation/quick-start/#launching-the-garage-server> for examples.";
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = types.submodule {
|
|
|
|
freeformType = toml.type;
|
|
|
|
|
|
|
|
options = {
|
|
|
|
metadata_dir = mkOption {
|
|
|
|
default = "/var/lib/garage/meta";
|
|
|
|
type = types.path;
|
|
|
|
description = lib.mdDoc "The metadata directory, put this on a fast disk (e.g. SSD) if possible.";
|
|
|
|
};
|
|
|
|
|
|
|
|
data_dir = mkOption {
|
|
|
|
default = "/var/lib/garage/data";
|
|
|
|
type = types.path;
|
|
|
|
description = lib.mdDoc "The main data storage, put this on your large storage (e.g. high capacity HDD)";
|
|
|
|
};
|
|
|
|
|
|
|
|
replication_mode = mkOption {
|
|
|
|
default = "none";
|
2023-07-15 17:15:38 +00:00
|
|
|
type = types.enum ([ "none" "1" "2" "3" "2-dangerous" "3-dangerous" "3-degraded" 1 2 3 ]);
|
2022-10-30 15:09:59 +00:00
|
|
|
apply = v: toString v;
|
2023-04-12 12:48:02 +00:00
|
|
|
description = lib.mdDoc "Garage replication mode, defaults to none, see: <https://garagehq.deuxfleurs.fr/documentation/reference-manual/configuration/#replication-mode> for reference.";
|
2022-10-30 15:09:59 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-04-12 12:48:02 +00:00
|
|
|
description = lib.mdDoc "Garage configuration, see <https://garagehq.deuxfleurs.fr/documentation/reference-manual/configuration/> for reference.";
|
2022-10-30 15:09:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2023-10-19 13:55:26 +00:00
|
|
|
description = lib.mdDoc "Garage package to use, needs to be set explicitly. If you are upgrading from a major version, please read NixOS and Garage release notes for upgrade instructions.";
|
2022-10-30 15:09:59 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment.etc."garage.toml" = {
|
|
|
|
source = configFile;
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ cfg.package ]; # For administration
|
|
|
|
|
|
|
|
systemd.services.garage = {
|
|
|
|
description = "Garage Object Storage (S3 compatible)";
|
|
|
|
after = [ "network.target" "network-online.target" ];
|
|
|
|
wants = [ "network.target" "network-online.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2023-10-09 19:29:22 +00:00
|
|
|
restartTriggers = [ configFile ] ++ (lib.optional (cfg.environmentFile != null) cfg.environmentFile);
|
2022-10-30 15:09:59 +00:00
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${cfg.package}/bin/garage server";
|
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
StateDirectory = mkIf (hasPrefix "/var/lib/garage" cfg.settings.data_dir || hasPrefix "/var/lib/garage" cfg.settings.metadata_dir) "garage";
|
2022-10-30 15:09:59 +00:00
|
|
|
DynamicUser = lib.mkDefault true;
|
|
|
|
ProtectHome = true;
|
|
|
|
NoNewPrivileges = true;
|
2023-10-09 19:29:22 +00:00
|
|
|
EnvironmentFile = lib.optional (cfg.environmentFile != null) cfg.environmentFile;
|
2022-10-30 15:09:59 +00:00
|
|
|
};
|
|
|
|
environment = {
|
|
|
|
RUST_LOG = lib.mkDefault "garage=${cfg.logLevel}";
|
|
|
|
} // cfg.extraEnvironment;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|