dotfiles/nixos/modules/services/forgejo.nix

108 lines
2.5 KiB
Nix
Raw Normal View History

2024-10-06 15:25:05 -05:00
{
flake,
config,
...
}: let
2024-11-04 20:49:43 -06:00
inherit (flake.config.machines.devices) server;
inherit (flake.config.services.instances) forgejo web;
2024-10-19 18:22:29 -05:00
service = forgejo;
localhost = web.localhost.address0;
host = "${service.subdomain}.${web.domains.url1}";
2024-10-06 15:25:05 -05:00
in {
services = {
forgejo = {
enable = true;
database.type = "postgres";
lfs.enable = true;
secrets = {
2024-10-19 18:22:29 -05:00
mailer.PASSWD = config.sops.secrets."${service.name}-smtp".path;
database.PASSWD = config.sops.secrets."${service.name}-database".path;
2024-10-06 15:25:05 -05:00
};
dump = {
interval = "5:00";
type = "zip";
file = "forgejo-backup";
enable = true;
};
settings = {
server = {
DOMAIN = host;
ROOT_URL = "https://${host}/";
2024-10-19 18:22:29 -05:00
HTTP_PORT = service.ports.port0;
2024-10-06 15:25:05 -05:00
};
# If you need to start from scratch, don't forget to turn this off again
service.DISABLE_REGISTRATION = false;
actions = {
ENABLED = true;
DEFAULT_ACTIONS_URL = "github";
};
mirror = {
ENABLED = true;
};
mailer = {
ENABLED = true;
SMTP_ADDR = "smtp.protonmail.ch";
2024-10-19 18:22:29 -05:00
FROM = service.email.address0;
USER = service.email.address0;
2024-10-06 15:25:05 -05:00
PROTOCOL = "smtp+starttls";
SMTP_PORT = 587;
SEND_AS_PLAIN_TEXT = true;
USE_CLIENT_CERT = false;
};
};
};
caddy = {
virtualHosts = {
"${host}" = {
extraConfig = ''
2024-10-19 18:22:29 -05:00
reverse_proxy ${localhost}:${toString service.ports.port0}
2024-10-06 15:25:05 -05:00
2024-10-19 18:22:29 -05:00
tls ${service.ssl.cert} ${service.ssl.key}
2024-10-06 15:25:05 -05:00
'';
};
};
};
};
sops = let
sopsPath = secret: {
2024-10-19 18:22:29 -05:00
path = "${service.sops.path0}/${service.name}-${secret}";
owner = service.name;
2024-10-06 15:25:05 -05:00
mode = "600";
};
in {
secrets = builtins.listToAttrs (
map
(secret: {
2024-10-19 18:22:29 -05:00
name = "${service.name}-${secret}";
2024-10-06 15:25:05 -05:00
value = sopsPath secret;
})
2024-11-04 02:09:15 -06:00
[
"smtp"
"database"
]
2024-10-06 15:25:05 -05:00
);
};
2024-10-19 18:22:29 -05:00
fileSystems."/var/lib/${service.name}" = {
device = service.paths.path0;
2024-10-06 15:25:05 -05:00
fsType = "none";
options = ["bind"];
depends = [server.storage0.mount];
};
systemd.tmpfiles.rules = [
2024-10-19 18:22:29 -05:00
"Z ${service.paths.path0} 755 ${service.name} ${service.name} -"
"Z ${service.sops.path0} 755 ${service.name} ${service.name} -"
2024-10-06 15:25:05 -05:00
];
2024-10-19 18:22:29 -05:00
users.users.${service.name}.extraGroups = ["caddy" "postgres"];
2024-10-06 15:25:05 -05:00
networking = {
firewall = {
allowedTCPPorts = [
2024-10-19 18:22:29 -05:00
service.ports.port0
2024-10-06 15:25:05 -05:00
];
};
};
}