2024-05-07 01:00:09 +02:00
|
|
|
{ config, my, pkgs, secrets, ... }:
|
2023-04-22 15:00:19 +02:00
|
|
|
|
|
|
|
let
|
2024-04-16 19:31:29 +02:00
|
|
|
inherit (my) domain;
|
|
|
|
fqdn = "srht.${domain}";
|
2024-05-07 01:00:09 +02:00
|
|
|
srhtServices = [
|
|
|
|
"metasrht"
|
|
|
|
"metasrht-api"
|
|
|
|
"metasrht-daily"
|
|
|
|
"metasrht-webhooks"
|
|
|
|
"gitsrht"
|
|
|
|
"gitsrht-api"
|
|
|
|
"gitsrht-periodic"
|
|
|
|
"gitsrht-webhooks"
|
|
|
|
];
|
|
|
|
secretNames = [
|
|
|
|
"network-key"
|
|
|
|
"service-key"
|
|
|
|
"oauth-client-secret"
|
|
|
|
"webhooks-privkey"
|
|
|
|
"pgp-pubkey"
|
|
|
|
"pgp-privkey"
|
|
|
|
];
|
2023-04-22 15:00:19 +02:00
|
|
|
in {
|
2024-05-07 01:00:09 +02:00
|
|
|
sops.secrets = builtins.listToAttrs (map (n: {
|
|
|
|
name = "sourcehut/${n}";
|
|
|
|
value = {
|
|
|
|
sopsFile = ../secrets/sops/sourcehut.yaml;
|
|
|
|
owner = "root";
|
|
|
|
group = "sourcehut";
|
|
|
|
mode = "0440";
|
|
|
|
restartUnits = map (srv: "${srv}.service") srhtServices;
|
|
|
|
};
|
|
|
|
}) secretNames);
|
2024-04-10 21:05:13 +02:00
|
|
|
|
2023-04-22 15:00:19 +02:00
|
|
|
services.sourcehut = {
|
|
|
|
enable = true;
|
|
|
|
redis.enable = true;
|
|
|
|
postgresql.enable = true;
|
2024-02-09 23:40:06 +01:00
|
|
|
|
|
|
|
listenAddress = "[::1]";
|
|
|
|
|
|
|
|
meta.enable = true;
|
|
|
|
|
2023-04-22 15:00:19 +02:00
|
|
|
git = {
|
|
|
|
enable = true;
|
|
|
|
user = "git";
|
|
|
|
};
|
|
|
|
|
|
|
|
nginx = {
|
|
|
|
enable = true;
|
2024-04-16 19:31:29 +02:00
|
|
|
virtualHost.useACMEHost = domain;
|
2023-04-22 15:00:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
settings = {
|
|
|
|
"sr.ht" = {
|
|
|
|
environment = "production";
|
|
|
|
global-domain = fqdn;
|
|
|
|
owner-name = "Christoph Heiss";
|
|
|
|
owner-email = "christoph@c8h4.io";
|
2024-05-07 01:00:09 +02:00
|
|
|
network-key = secrets."sourcehut/network-key".path;
|
|
|
|
service-key = secrets."sourcehut/service-key".path;
|
2023-04-22 15:00:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
"meta.sr.ht".origin = "https://meta.${fqdn}";
|
|
|
|
|
|
|
|
"meta.sr.ht::settings" = {
|
|
|
|
user-invites = 0;
|
|
|
|
registration = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
"git.sr.ht" = {
|
|
|
|
oauth-client-id = fqdn;
|
2024-05-07 01:00:09 +02:00
|
|
|
oauth-client-secret = secrets."sourcehut/oauth-client-secret".path;
|
2023-04-22 15:00:19 +02:00
|
|
|
outgoing-domain = "https://git.${fqdn}";
|
|
|
|
origin = "https://git.${fqdn}";
|
|
|
|
};
|
|
|
|
|
|
|
|
mail = {
|
|
|
|
smtp-from = "srht@c8h4.io";
|
|
|
|
pgp-key-id = "6C28803321A0F6C53B78A2AF3D84AB70408524DD";
|
2024-05-07 01:00:09 +02:00
|
|
|
pgp-pubkey = secrets."sourcehut/pgp-pubkey".path;
|
|
|
|
pgp-privkey = secrets."sourcehut/pgp-privkey".path;
|
2023-04-22 15:00:19 +02:00
|
|
|
};
|
|
|
|
|
2024-05-07 01:00:09 +02:00
|
|
|
webhooks.private-key = secrets."sourcehut/webhooks-privkey".path;
|
2023-04-22 15:00:19 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-01-31 00:13:42 +01:00
|
|
|
security.acme.certs."c8h4.io".extraDomainNames = [ "*.${fqdn}" ];
|
2023-04-22 15:00:19 +02:00
|
|
|
|
2023-05-02 22:56:16 +02:00
|
|
|
# Binds the sourcehut secrets path read-only into services that require them
|
2024-05-07 01:00:09 +02:00
|
|
|
systemd.services = builtins.listToAttrs (map (name: {
|
2023-05-02 22:56:16 +02:00
|
|
|
inherit name;
|
2024-05-07 01:00:09 +02:00
|
|
|
value.serviceConfig.BindReadOnlyPaths =
|
|
|
|
map (n: secrets."sourcehut/${n}".path) secretNames;
|
|
|
|
}) srhtServices);
|
2023-04-22 15:00:19 +02:00
|
|
|
|
2023-12-02 19:39:28 +01:00
|
|
|
services.openssh.settings.AllowUsers = [ "git" ];
|
2023-04-22 15:00:19 +02:00
|
|
|
|
2024-05-07 01:00:09 +02:00
|
|
|
users.groups.sourcehut = { };
|
|
|
|
|
2023-12-02 23:48:32 +01:00
|
|
|
users.users = {
|
|
|
|
git = {
|
|
|
|
# Disable login for `git` user
|
|
|
|
password = "*";
|
2024-05-07 01:00:09 +02:00
|
|
|
extraGroups = [ "restic-backup" "sourcehut" ];
|
2023-12-02 23:48:32 +01:00
|
|
|
};
|
2024-05-07 01:00:09 +02:00
|
|
|
metasrht.extraGroups = [ "sourcehut" ];
|
2023-12-02 23:48:32 +01:00
|
|
|
};
|
|
|
|
|
2024-05-20 15:51:16 +02:00
|
|
|
services.nginx.virtualHosts."git.${domain}" = {
|
|
|
|
forceSSL = true;
|
|
|
|
useACMEHost = my.domain;
|
|
|
|
kTLS = true;
|
|
|
|
# `globalRedirect` appends `$request_uri` to the target, which we do not want here
|
|
|
|
locations."/".return = "https://git.${fqdn}";
|
|
|
|
};
|
|
|
|
|
2024-05-07 01:00:09 +02:00
|
|
|
services.restic.backups.gitsrht = {
|
|
|
|
environmentFile = secrets."restic/rest-env".path;
|
2023-12-02 23:48:32 +01:00
|
|
|
initialize = true;
|
2024-05-07 01:00:09 +02:00
|
|
|
repository =
|
|
|
|
"${my.homelab.services.restic.repositoryBase}/${config.networking.hostName}";
|
|
|
|
passwordFile = secrets."restic/repo-password".path;
|
2023-12-02 23:48:32 +01:00
|
|
|
user = "git";
|
|
|
|
paths = [ "/var/lib/sourcehut/gitsrht" ];
|
2023-12-03 21:41:32 +01:00
|
|
|
timerConfig.OnCalendar = "*-*-* 4:15:00"; # daily at 04:15
|
2023-12-03 21:42:58 +01:00
|
|
|
backupCleanupCommand = my.mkResticBackupNotificationCmd {
|
|
|
|
name = "gitsrht";
|
2024-05-07 01:00:09 +02:00
|
|
|
inherit pkgs secrets;
|
2023-12-03 21:42:58 +01:00
|
|
|
};
|
2023-12-02 23:48:32 +01:00
|
|
|
};
|
2023-04-22 15:00:19 +02:00
|
|
|
}
|