{ flake, config, ... }: let inherit (flake.config.people) user0; inherit (flake.config.people.user.${user0}) domain email; inherit (flake.config.system.device) server wildcard; inherit (flake.config.service.instance.forgejo) paths ports name subdomain sops ssl; localhost = wildcard.ip.address0; host = "${subdomain}.${domain.url1}"; in { services = { forgejo = { enable = true; database.type = "postgres"; lfs.enable = true; secrets = { mailer.PASSWD = config.sops.secrets."${name}-smtp".path; database.PASSWD = config.sops.secrets."${name}-database".path; }; dump = { interval = "5:00"; type = "zip"; file = "forgejo-backup"; enable = true; }; settings = { server = { DOMAIN = host; ROOT_URL = "https://${host}/"; HTTP_PORT = ports.port0; }; # 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"; FROM = email.address5; USER = email.address5; PROTOCOL = "smtp+starttls"; SMTP_PORT = 587; SEND_AS_PLAIN_TEXT = true; USE_CLIENT_CERT = false; }; }; }; caddy = { virtualHosts = { "${host}" = { extraConfig = '' reverse_proxy ${localhost}:${toString ports.port0} tls ${ssl.cert} ${ssl.key} ''; }; }; }; }; sops = let sopsSecrets = ["smtp" "database"]; sopsPath = secret: { path = "${sops.path0}/${name}-${secret}"; owner = name; mode = "600"; }; in { secrets = builtins.listToAttrs ( map (secret: { name = "${name}-${secret}"; value = sopsPath secret; }) sopsSecrets ); }; fileSystems."/var/lib/${name}" = { device = paths.path0; fsType = "none"; options = ["bind"]; depends = [server.storage0.mount]; }; systemd.tmpfiles.rules = [ "Z ${paths.path0} 755 ${name} ${name} -" "Z ${sops.path0} 755 ${name} ${name} -" ]; users.users.${name}.extraGroups = ["caddy" "postgres"]; networking = { firewall = { allowedTCPPorts = [ ports.port0 ]; }; }; }