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 {
96 environment.etc."garage.toml" = {
101 environment.systemPackages = [
102 (pkgs.writeScriptBin "garage" ''
103 # make it so all future variables set are automatically exported as environment variables
106 # 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)
107 [ -f ${lib.escapeShellArg cfg.environmentFile} ] && . ${lib.escapeShellArg cfg.environmentFile}
109 # exec the program with quoted args (also with shell arg escaping for the program path to avoid quoting issues there)
110 exec ${lib.escapeShellArg (lib.getExe cfg.package)} "$@"
114 systemd.services.garage = {
115 description = "Garage Object Storage (S3 compatible)";
118 "network-online.target"
122 "network-online.target"
124 wantedBy = [ "multi-user.target" ];
127 ] ++ (lib.optional (cfg.environmentFile != null) cfg.environmentFile);
129 ExecStart = "${cfg.package}/bin/garage server";
131 StateDirectory = mkIf (
132 anyHasPrefix "/var/lib/garage" cfg.settings.data_dir
133 || hasPrefix "/var/lib/garage" cfg.settings.metadata_dir
135 DynamicUser = lib.mkDefault true;
137 NoNewPrivileges = true;
138 EnvironmentFile = lib.optional (cfg.environmentFile != null) cfg.environmentFile;
141 RUST_LOG = lib.mkDefault "garage=${cfg.logLevel}";
142 } // cfg.extraEnvironment;