infrastructure/machines/storage01/garage.nix

140 lines
3 KiB
Nix
Raw Normal View History

{
config,
lib,
pkgs,
...
}:
2023-09-11 11:17:52 +02:00
let
inherit (lib) mapAttrs' nameValuePair;
2023-09-11 11:17:52 +02:00
host = "s3.dgnum.eu";
webHost = "cdn.dgnum.eu";
data_dir = "/data/slow/garage/data";
metadata_dir = "/data/fast/garage/meta";
domains = [
2024-09-22 00:52:04 +02:00
"bandarretdurgence.ens.fr"
"boussole-sante.normalesup.eu"
2024-09-22 00:52:04 +02:00
"lanuit.ens.fr"
"simi.normalesup.eu"
];
buckets = [
"monorepo-terraform-state"
2024-09-22 00:52:04 +02:00
"banda-website"
"castopod-dgnum"
2024-09-22 00:52:04 +02:00
"hackens-website"
"nuit-website"
"peertube-videos-dgnum"
] ++ domains;
mkHosted = host: builtins.map (b: "${b}.${host}");
ports = {
admin_api = 3903;
k2v_api = 3904;
rpc = 3901;
s3_api = 3900;
s3_web = 3902;
};
in
{
dgn-web.internalPorts = mapAttrs' (name: nameValuePair "garage-${name}") ports;
2023-09-11 11:17:52 +02:00
services.garage = {
enable = true;
2024-10-06 15:29:20 +02:00
package = pkgs.garage_1_0_1;
2023-09-11 11:17:52 +02:00
settings = {
inherit data_dir metadata_dir;
db_engine = "lmdb";
2024-10-02 19:20:17 +02:00
replication_mode = "none"; # TODO: deprecated
2023-09-11 11:17:52 +02:00
compression_level = 7;
rpc_bind_addr = "[::]:${toString ports.rpc}";
rpc_public_addr = "127.0.0.1:${toString ports.rpc}";
2023-09-11 11:17:52 +02:00
s3_api = {
s3_region = "garage";
api_bind_addr = "127.0.0.1:${toString ports.s3_api}";
2023-09-11 11:17:52 +02:00
root_domain = ".${host}";
};
s3_web = {
bind_addr = "127.0.0.1:${toString ports.s3_web}";
2023-09-11 11:17:52 +02:00
root_domain = ".${webHost}";
index = "index.html";
};
k2v_api.api_bind_addr = "[::]:${toString ports.k2v_api}";
2023-09-11 11:17:52 +02:00
admin.api_bind_addr = "127.0.0.1:${toString ports.admin_api}";
2023-09-11 11:17:52 +02:00
};
environmentFile = config.age.secrets."garage-environment_file".path;
2023-09-11 11:17:52 +02:00
};
systemd.services.garage.serviceConfig = {
User = "garage";
ReadWriteDirectories = [
data_dir
metadata_dir
];
2024-10-02 19:20:17 +02:00
TimeoutSec = 600;
};
users.users.garage = {
isSystemUser = true;
group = "garage";
};
users.groups.garage = { };
services.nginx.virtualHosts = {
"s3-admin.dgnum.eu" = {
enableACME = true;
forceSSL = true;
locations."/".extraConfig = ''
proxy_pass http://127.0.0.1:${toString ports.admin_api};
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
'';
};
${host} = {
enableACME = true;
forceSSL = true;
serverAliases = mkHosted host buckets;
locations."/".extraConfig = ''
proxy_pass http://127.0.0.1:${toString ports.s3_api};
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
# Disable buffering to a temporary file.
proxy_max_temp_file_size 0;
client_max_body_size 5G;
'';
};
${webHost} = {
enableACME = true;
forceSSL = true;
serverAliases = domains ++ (mkHosted webHost buckets);
locations."/".extraConfig = ''
proxy_pass http://127.0.0.1:${toString ports.s3_web};
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
'';
};
2023-09-11 11:17:52 +02:00
};
}