11 cfg = config.services.garage;
12 toml = pkgs.formats.toml { };
13 configFile = toml.generate "garage.toml" cfg.settings;
17 if isString strOrList then
18 hasPrefix prefix strOrList
20 any ({ path, ... }: hasPrefix prefix path) strOrList;
25 maintainers = [ maintainers.mjm ];
28 options.services.garage = {
29 enable = mkEnableOption "Garage Object Storage (S3 compatible)";
31 extraEnvironment = mkOption {
32 type = types.attrsOf types.str;
33 description = "Extra environment variables to pass to the Garage server.";
36 RUST_BACKTRACE = "yes";
40 environmentFile = mkOption {
41 type = types.nullOr types.path;
42 description = "File containing environment variables to be passed to the Garage server.";
56 description = "Garage log level, see <https://garagehq.deuxfleurs.fr/documentation/quick-start/#launching-the-garage-server> for examples.";
60 type = types.submodule {
61 freeformType = toml.type;
64 metadata_dir = mkOption {
65 default = "/var/lib/garage/meta";
67 description = "The metadata directory, put this on a fast disk (e.g. SSD) if possible.";
71 default = "/var/lib/garage/data";
74 path = "/var/lib/garage/data";
78 type = with types; either path (listOf attrs);
80 The directory in which Garage will store the data blocks of objects. This folder can be placed on an HDD.
81 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.
86 description = "Garage configuration, see <https://garagehq.deuxfleurs.fr/documentation/reference-manual/configuration/> for reference.";
91 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.";
95 config = mkIf cfg.enable {
98 # We removed our module-level default for replication_mode. If a user upgraded
99 # to garage 1.0.0 while relying on the module-level default, they would be left
100 # with a config which evaluates and builds, but then garage refuses to start
101 # because either replication_factor or replication_mode is required.
102 # The replication_factor option also was `toString`'ed before, which is
103 # now not possible anymore, so we prompt the user to change it to a string
105 # These assertions can be removed in NixOS 24.11, when all users have been
109 (cfg.settings ? replication_factor || cfg.settings ? replication_mode)
110 || lib.versionOlder cfg.package.version "1.0.0";
112 Garage 1.0.0 requires an explicit replication factor to be set.
113 Please set replication_factor to 1 explicitly to preserve the previous behavior.
114 https://git.deuxfleurs.fr/Deuxfleurs/garage/src/tag/v1.0.0/doc/book/reference-manual/configuration.md#replication_factor
119 assertion = lib.isString (cfg.settings.replication_mode or "");
121 The explicit `replication_mode` option in `services.garage.settings`
122 has been removed and is now handled by the freeform settings in order
123 to allow it being completely absent (for Garage 1.x).
124 That module option previously `toString`'ed the value it's configured
125 with, which is now no longer possible.
127 You're still using a non-string here, please manually set it to
128 a string, or migrate to the separate setting keys introduced in 1.x.
130 Refer to https://garagehq.deuxfleurs.fr/documentation/working-documents/migration-1/
131 for the migration guide.
136 environment.etc."garage.toml" = {
141 environment.systemPackages = [
142 (pkgs.writeScriptBin "garage" ''
143 # make it so all future variables set are automatically exported as environment variables
146 # 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)
147 [ -f ${lib.escapeShellArg cfg.environmentFile} ] && . ${lib.escapeShellArg cfg.environmentFile}
149 # exec the program with quoted args (also with shell arg escaping for the program path to avoid quoting issues there)
150 exec ${lib.escapeShellArg (lib.getExe cfg.package)} "$@"
154 systemd.services.garage = {
155 description = "Garage Object Storage (S3 compatible)";
158 "network-online.target"
162 "network-online.target"
164 wantedBy = [ "multi-user.target" ];
167 ] ++ (lib.optional (cfg.environmentFile != null) cfg.environmentFile);
169 ExecStart = "${cfg.package}/bin/garage server";
171 StateDirectory = mkIf (
172 anyHasPrefix "/var/lib/garage" cfg.settings.data_dir
173 || hasPrefix "/var/lib/garage" cfg.settings.metadata_dir
175 DynamicUser = lib.mkDefault true;
177 NoNewPrivileges = true;
178 EnvironmentFile = lib.optional (cfg.environmentFile != null) cfg.environmentFile;
181 RUST_LOG = lib.mkDefault "garage=${cfg.logLevel}";
182 } // cfg.extraEnvironment;