1 { config, lib, pkgs, ... }:
6 cfg = config.services.garage;
7 toml = pkgs.formats.toml { };
8 configFile = toml.generate "garage.toml" cfg.settings;
13 maintainers = with pkgs.lib.maintainers; [ raitobezarius ];
16 options.services.garage = {
17 enable = mkEnableOption (lib.mdDoc "Garage Object Storage (S3 compatible)");
19 extraEnvironment = mkOption {
20 type = types.attrsOf types.str;
21 description = lib.mdDoc "Extra environment variables to pass to the Garage server.";
23 example = { RUST_BACKTRACE = "yes"; };
26 environmentFile = mkOption {
27 type = types.nullOr types.path;
28 description = lib.mdDoc "File containing environment variables to be passed to the Garage server.";
33 type = types.enum ([ "info" "debug" "trace" ]);
36 description = lib.mdDoc "Garage log level, see <https://garagehq.deuxfleurs.fr/documentation/quick-start/#launching-the-garage-server> for examples.";
40 type = types.submodule {
41 freeformType = toml.type;
44 metadata_dir = mkOption {
45 default = "/var/lib/garage/meta";
47 description = lib.mdDoc "The metadata directory, put this on a fast disk (e.g. SSD) if possible.";
51 default = "/var/lib/garage/data";
53 description = lib.mdDoc "The main data storage, put this on your large storage (e.g. high capacity HDD)";
56 replication_mode = mkOption {
58 type = types.enum ([ "none" "1" "2" "3" "2-dangerous" "3-dangerous" "3-degraded" 1 2 3 ]);
59 apply = v: toString v;
60 description = lib.mdDoc "Garage replication mode, defaults to none, see: <https://garagehq.deuxfleurs.fr/documentation/reference-manual/configuration/#replication-mode> for reference.";
64 description = lib.mdDoc "Garage configuration, see <https://garagehq.deuxfleurs.fr/documentation/reference-manual/configuration/> for reference.";
69 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.";
73 config = mkIf cfg.enable {
74 environment.etc."garage.toml" = {
78 environment.systemPackages = [ cfg.package ]; # For administration
80 systemd.services.garage = {
81 description = "Garage Object Storage (S3 compatible)";
82 after = [ "network.target" "network-online.target" ];
83 wants = [ "network.target" "network-online.target" ];
84 wantedBy = [ "multi-user.target" ];
85 restartTriggers = [ configFile ] ++ (lib.optional (cfg.environmentFile != null) cfg.environmentFile);
87 ExecStart = "${cfg.package}/bin/garage server";
89 StateDirectory = mkIf (hasPrefix "/var/lib/garage" cfg.settings.data_dir || hasPrefix "/var/lib/garage" cfg.settings.metadata_dir) "garage";
90 DynamicUser = lib.mkDefault true;
92 NoNewPrivileges = true;
93 EnvironmentFile = lib.optional (cfg.environmentFile != null) cfg.environmentFile;
96 RUST_LOG = lib.mkDefault "garage=${cfg.logLevel}";
97 } // cfg.extraEnvironment;