feat(garage): Simplify management of domains and buckets

This commit is contained in:
Tom Hubrecht 2024-03-16 17:34:42 +01:00
parent f74fd8c8eb
commit 9cae38be02

View file

@ -1,9 +1,4 @@
{
config,
pkgs,
lib,
...
}:
{ config, pkgs, ... }:
let
host = "s3.dgnum.eu";
@ -12,16 +7,17 @@ let
data_dir = "/data/slow/garage/data";
metadata_dir = "/data/fast/garage/meta";
buckets = {
"castopod-dgnum" = { };
"peertube-videos-dgnum" = { };
"boussole-sante.normalesup.eu" = {
mainDomain = true;
};
"simi.normalesup.eu" = {
mainDomain = true;
};
};
domains = [
"boussole-sante.normalesup.eu"
"simi.normalesup.eu"
];
buckets = [
"castopod-dgnum"
"peertube-videos-dgnum"
] ++ domains;
mkHosted = host: builtins.map (b: "${b}.${host}");
in
{
services.garage = {
@ -79,7 +75,7 @@ in
enableACME = true;
forceSSL = true;
serverAliases = builtins.map (b: "${b}.${host}") (builtins.attrNames buckets);
serverAliases = mkHosted host buckets;
locations."/".extraConfig = ''
proxy_pass http://127.0.0.1:3900;
@ -95,16 +91,13 @@ in
enableACME = true;
forceSSL = true;
serverAliases = lib.flatten (
lib.mapAttrsToList (
b: v: lib.singleton "${b}.${webHost}" ++ lib.optional (v ? mainDomain && v.mainDomain) b
) buckets
);
serverAliases = domains ++ (mkHosted webHost buckets);
locations."/".extraConfig = ''
proxy_pass http://127.0.0.1:3902;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;'';
proxy_set_header Host $host;
'';
};
};
}