dotfiles/modules/nixos/services/forgejo/default.nix

121 lines
2.7 KiB
Nix
Raw Normal View History

2024-10-06 15:25:05 -05:00
{
flake,
config,
...
2025-01-18 17:05:54 -06:00
}:
let
inherit (flake.config.machines.devices)
ceres
2025-01-08 19:06:14 -06:00
;
2025-02-02 21:16:28 -06:00
inherit (flake.config.services.instances) smtp forgejo web;
2024-10-19 18:22:29 -05:00
service = forgejo;
localhost = web.localhost.address0;
2025-01-18 17:05:54 -06:00
host = "${service.subdomain}.${web.domains.url3}";
in
{
2024-10-06 15:25:05 -05:00
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;
2024-11-23 21:27:02 -06:00
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
2025-01-19 01:59:28 -06:00
service.DISABLE_REGISTRATION = true;
2024-10-06 15:25:05 -05:00
actions = {
ENABLED = true;
DEFAULT_ACTIONS_URL = "github";
};
mirror = {
ENABLED = true;
};
mailer = {
ENABLED = true;
2025-02-02 21:16:28 -06:00
SMTP_ADDR = smtp.hostname;
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";
2025-02-02 21:16:28 -06:00
SMTP_PORT = smtp.ports.port0;
2024-10-06 15:25:05 -05:00
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
'';
};
};
};
};
2025-01-18 17:05:54 -06:00
sops =
let
sopsPath = secret: {
path = "${service.sops.path0}/${service.name}-${secret}";
owner = service.name;
mode = "600";
};
in
{
secrets = builtins.listToAttrs (
map
(secret: {
name = "${service.name}-${secret}";
value = sopsPath secret;
})
[
"smtp"
"database"
]
);
2024-10-06 15:25:05 -05:00
};
2025-01-18 22:32:54 -06:00
fileSystems."/var/lib/${service.name}" = {
device = service.paths.path0;
fsType = "none";
options = [
"bind"
];
depends = [
ceres.storage0.mount
2025-01-18 22:32:54 -06:00
];
};
2024-10-06 15:25:05 -05:00
2024-11-23 21:28:17 -06:00
systemd.tmpfiles.rules = [
"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
2025-01-08 19:06:14 -06: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
];
};
};
}