1 { config, lib, pkgs, ... }:
6 cfg = config.services.garage;
7 toml = pkgs.formats.toml {};
8 configFile = toml.generate "garage.toml" cfg.settings;
11 meta.maintainers = [ maintainers.raitobezarius ];
13 options.services.garage = {
14 enable = mkEnableOption (lib.mdDoc "Garage Object Storage (S3 compatible)");
16 extraEnvironment = mkOption {
17 type = types.attrsOf types.str;
18 description = lib.mdDoc "Extra environment variables to pass to the Garage server.";
20 example = { RUST_BACKTRACE="yes"; };
24 type = types.enum (["info" "debug" "trace"]);
27 description = lib.mdDoc "Garage log level, see <https://garagehq.deuxfleurs.fr/documentation/quick-start/#launching-the-garage-server> for examples.";
31 type = types.submodule {
32 freeformType = toml.type;
35 metadata_dir = mkOption {
36 default = "/var/lib/garage/meta";
38 description = lib.mdDoc "The metadata directory, put this on a fast disk (e.g. SSD) if possible.";
42 default = "/var/lib/garage/data";
44 description = lib.mdDoc "The main data storage, put this on your large storage (e.g. high capacity HDD)";
47 replication_mode = mkOption {
49 type = types.enum ([ "none" "1" "2" "3" 1 2 3 ]);
50 apply = v: toString v;
51 description = lib.mdDoc "Garage replication mode, defaults to none, see: <https://garagehq.deuxfleurs.fr/reference_manual/configuration.html#replication_mode> for reference.";
55 description = lib.mdDoc "Garage configuration, see <https://garagehq.deuxfleurs.fr/reference_manual/configuration.html> for reference.";
59 default = pkgs.garage;
60 defaultText = literalExpression "pkgs.garage";
62 description = lib.mdDoc "Garage package to use.";
66 config = mkIf cfg.enable {
67 environment.etc."garage.toml" = {
71 environment.systemPackages = [ cfg.package ]; # For administration
73 systemd.services.garage = {
74 description = "Garage Object Storage (S3 compatible)";
75 after = [ "network.target" "network-online.target" ];
76 wants = [ "network.target" "network-online.target" ];
77 wantedBy = [ "multi-user.target" ];
79 ExecStart = "${cfg.package}/bin/garage server";
81 StateDirectory = mkIf (hasPrefix "/var/lib/garage" cfg.settings.data_dir && hasPrefix "/var/lib/garage" cfg.settings.metadata_dir) "garage";
82 DynamicUser = lib.mkDefault true;
84 NoNewPrivileges = true;
87 RUST_LOG = lib.mkDefault "garage=${cfg.logLevel}";
88 } // cfg.extraEnvironment;