depot/cluster/services/attic/server.nix

93 lines
2.1 KiB
Nix
Raw Normal View History

2023-10-31 23:19:08 +02:00
{ cluster, config, depot, lib, ... }:
2023-06-14 00:27:53 +03:00
let
inherit (cluster.config.services.attic) secrets;
2024-08-02 23:46:45 +03:00
link = cluster.config.hostLinks.${config.networking.hostName}.attic;
isMonolith = lib.elem config.networking.hostName cluster.config.services.attic.nodes.monolith;
2023-06-14 00:27:53 +03:00
in
{
services.locksmith.waitForSecrets.atticd = [ "garage-attic" ];
2023-06-14 00:27:53 +03:00
services.atticd = {
enable = true;
package = depot.inputs.attic.packages.attic-server;
2023-06-14 00:27:53 +03:00
environmentFile = secrets.serverToken.path;
2024-08-02 23:46:45 +03:00
mode = if isMonolith then "monolithic" else "api-server";
2023-06-14 00:27:53 +03:00
settings = {
2024-08-02 23:46:45 +03:00
listen = link.tuple;
2023-06-14 00:27:53 +03:00
chunking = {
2023-10-31 23:19:08 +02:00
nar-size-threshold = 0;
min-size = 0;
avg-size = 0;
max-size = 0;
2023-06-14 00:27:53 +03:00
};
2023-10-31 23:19:08 +02:00
compression.type = "none";
database.url = "postgresql://attic@${cluster.config.links.patroni-pg-access.tuple}/attic";
2023-06-14 00:27:53 +03:00
storage = {
2023-10-31 23:19:08 +02:00
type = "s3";
region = "us-east-1";
endpoint = cluster.config.links.garageS3.url;
2023-10-31 23:19:08 +02:00
bucket = "attic";
2023-06-14 00:27:53 +03:00
};
garbage-collection = {
interval = "2 weeks";
default-retention-period = "3 months";
};
2023-06-14 00:27:53 +03:00
};
};
users = {
users.atticd = {
isSystemUser = true;
group = "atticd";
home = "/var/lib/atticd";
createHome = true;
};
groups.atticd = {};
};
2023-10-31 23:19:08 +02:00
systemd.services.atticd = {
after = [ "postgresql.service" ];
2024-08-02 23:46:45 +03:00
distributed = lib.mkIf isMonolith {
enable = true;
registerService = "atticd";
};
serviceConfig = {
DynamicUser = lib.mkForce false;
2024-08-02 23:46:45 +03:00
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" "AF_NETLINK" ];
};
2023-10-31 23:19:08 +02:00
environment = {
AWS_SHARED_CREDENTIALS_FILE = "/run/locksmith/garage-attic";
PGPASSFILE = secrets.dbCredentials.path;
2023-10-31 23:19:08 +02:00
};
};
2023-06-14 00:27:53 +03:00
2024-08-02 23:46:45 +03:00
consul.services.atticd = {
mode = if isMonolith then "manual" else "direct";
definition = {
name = "atticd";
id = "atticd-${config.services.atticd.mode}";
2024-08-02 23:46:45 +03:00
address = link.ipv4;
inherit (link) port;
checks = [
{
name = "Attic Server";
id = "service:atticd:backend";
interval = "5s";
http = link.url;
}
];
};
};
2023-06-14 00:27:53 +03:00
}