1 { config, lib, pkgs, ... }:
6 cfg = config.services.garage;
7 toml = pkgs.formats.toml { };
8 configFile = toml.generate "garage.toml" cfg.settings;
16 options.services.garage = {
17 enable = mkEnableOption "Garage Object Storage (S3 compatible)";
19 extraEnvironment = mkOption {
20 type = types.attrsOf types.str;
21 description = "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 = "File containing environment variables to be passed to the Garage server.";
33 type = types.enum ([ "error" "warn" "info" "debug" "trace" ]);
36 description = "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 = "The metadata directory, put this on a fast disk (e.g. SSD) if possible.";
51 default = "/var/lib/garage/data";
53 path = "/var/lib/garage/data";
56 type = with types; either path (listOf attrs);
58 The directory in which Garage will store the data blocks of objects. This folder can be placed on an HDD.
59 Since v0.9.0, Garage supports multiple data directories, refer to https://garagehq.deuxfleurs.fr/documentation/reference-manual/configuration/#data_dir for the exact format.
64 description = "Garage configuration, see <https://garagehq.deuxfleurs.fr/documentation/reference-manual/configuration/> for reference.";
69 description = "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 {
76 # We removed our module-level default for replication_mode. If a user upgraded
77 # to garage 1.0.0 while relying on the module-level default, they would be left
78 # with a config which evaluates and builds, but then garage refuses to start
79 # because either replication_factor or replication_mode is required.
80 # The replication_factor option also was `toString`'ed before, which is
81 # now not possible anymore, so we prompt the user to change it to a string
83 # These assertions can be removed in NixOS 24.11, when all users have been
86 assertion = (cfg.settings ? replication_factor || cfg.settings ? replication_mode) || lib.versionOlder cfg.package.version "1.0.0";
88 Garage 1.0.0 requires an explicit replication factor to be set.
89 Please set replication_factor to 1 explicitly to preserve the previous behavior.
90 https://git.deuxfleurs.fr/Deuxfleurs/garage/src/tag/v1.0.0/doc/book/reference-manual/configuration.md#replication_factor
95 assertion = lib.isString (cfg.settings.replication_mode or "");
97 The explicit `replication_mode` option in `services.garage.settings`
98 has been removed and is now handled by the freeform settings in order
99 to allow it being completely absent (for Garage 1.x).
100 That module option previously `toString`'ed the value it's configured
101 with, which is now no longer possible.
103 You're still using a non-string here, please manually set it to
104 a string, or migrate to the separate setting keys introduced in 1.x.
106 Refer to https://garagehq.deuxfleurs.fr/documentation/working-documents/migration-1/
107 for the migration guide.
112 environment.etc."garage.toml" = {
117 environment.systemPackages = [
118 (pkgs.writeScriptBin "garage" ''
119 # make it so all future variables set are automatically exported as environment variables
122 # source the set environmentFile (since systemd EnvironmentFile is supposed to be a minor subset of posix sh parsing) (with shell arg escaping to avoid quoting issues)
123 [ -f ${lib.escapeShellArg cfg.environmentFile} ] && . ${lib.escapeShellArg cfg.environmentFile}
125 # exec the program with quoted args (also with shell arg escaping for the program path to avoid quoting issues there)
126 exec ${lib.escapeShellArg (lib.getExe cfg.package)} "$@"
130 systemd.services.garage = {
131 description = "Garage Object Storage (S3 compatible)";
132 after = [ "network.target" "network-online.target" ];
133 wants = [ "network.target" "network-online.target" ];
134 wantedBy = [ "multi-user.target" ];
135 restartTriggers = [ configFile ] ++ (lib.optional (cfg.environmentFile != null) cfg.environmentFile);
137 ExecStart = "${cfg.package}/bin/garage server";
139 StateDirectory = mkIf (hasPrefix "/var/lib/garage" cfg.settings.data_dir || hasPrefix "/var/lib/garage" cfg.settings.metadata_dir) "garage";
140 DynamicUser = lib.mkDefault true;
142 NoNewPrivileges = true;
143 EnvironmentFile = lib.optional (cfg.environmentFile != null) cfg.environmentFile;
146 RUST_LOG = lib.mkDefault "garage=${cfg.logLevel}";
147 } // cfg.extraEnvironment;