Jump to content

Garage

From Official NixOS Wiki
Revision as of 01:01, 24 November 2026 by Nicof2000 (talk | contribs) (setup/finalCode: change order to match text)

Garage is an open-source, self-hostable S3 store, for geodistributed stores.

It is documented in the NixOS manual.

Setup

You have to explicitly set the package option. You can choose between the garage_1 and garage_2 packages.

For a minimal setup you need to configure rpc_bind_addr, s3_api.s3_region, replication_factor and rpc_secret_file.

The Garage systemd service has DynamicUser configured, which prevents you from setting the owner property of the secret.

Adding the secret without it like this:

{ config, ... }:
{
  sops.secrets."garage/rpc_secret" = { };
  services.garage.settings.rpc_secret_file = config.sops.secrets."garage/rpc_secret".path;
}

Results in: Error: Failed to read secret file /run/secrets/garage/rpc_secret: Permission denied (os error 13) You can use systemd LoadCredential to make it accessible for the dynamic user running the service:

{ config, ... }:
{
  sops.secrets."garage/rpc_secret" = { };
  services.garage.settings.rpc_secret_file = "/run/credentials/garage.service/rpc_secret";
  systemd.services.garage.serviceConfig.LoadCredential =
    "rpc_secret:${config.sops.secrets."garage/rpc_secret".path}";
}

However this results in another error in the Garage service:

2026-11-24T00:20:43.071157Z  INFO garage::server: Loading configuration from /etc/garage.toml...
Error: File /run/credentials/garage.service/rpc_secret is world-readable! (mode: 0100440, expected 0600)
Refusing to start until this is fixed, or environment variable GARAGE_ALLOW_WORLD_READABLE_SECRETS is set to true.

This is because garage expects the file to have a umask of 600, not 440. To accept this umask (which is secure, as you can see in the following codeblock) you can set the allow_world_readable_secrets setting.

# systemctl start garage; getfacl /run/credentials/garage.service/rpc_secret
getfacl: Removing leading '/' from absolute path names
# file: run/credentials/garage.service/rpc_secret
# owner: root
# group: root
user::r--
user:garage:r--
group::---
mask::r--
other::---

The final configuration looks like this:

{ config, pkgs, ... }:
{
  sops.secrets."garage/rpc_secret" = { };

  services.garage = {
    enable = true;
    package = pkgs.garage_2;
    settings = {
      rpc_bind_addr = "[::]:3901";
      replication_factor = 1;
      s3_api.s3_region = "garage";
      rpc_secret_file = "/run/credentials/garage.service/rpc_secret";
      allow_world_readable_secrets = true;
    };
  };

  systemd.services.garage.serviceConfig.LoadCredential =
    "rpc_secret:${config.sops.secrets."garage/rpc_secret".path}";
}