2023-10-28 19:46:18 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
2023-10-28 21:55:39 +00:00
|
|
|
flake,
|
2023-10-28 19:46:18 +00:00
|
|
|
...
|
|
|
|
}:
|
|
|
|
{
|
|
|
|
age.secrets.forgejo-database-password = {
|
2023-10-28 21:55:39 +00:00
|
|
|
file = "${flake.self}/secrets/forgejo-database-password.age";
|
2023-10-28 19:46:18 +00:00
|
|
|
mode = "600";
|
|
|
|
owner = "gitea";
|
|
|
|
};
|
|
|
|
|
|
|
|
age.secrets.forgejo-mailer-password = {
|
2023-10-28 21:55:39 +00:00
|
|
|
file = "${flake.self}/secrets/forgejo-mailer-password.age";
|
2023-10-28 19:46:18 +00:00
|
|
|
mode = "600";
|
|
|
|
owner = "gitea";
|
|
|
|
};
|
|
|
|
|
2024-04-05 17:14:10 +00:00
|
|
|
age.secrets.forgejo-ssh-private-key = {
|
|
|
|
file = "${flake.self}/secrets/forgejo-ssh-private-key.age";
|
|
|
|
mode = "600";
|
|
|
|
owner = "gitea";
|
|
|
|
path = "/etc/forgejo/ssh/id_forgejo";
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc."forgejo/ssh/id_forgejo.pub" = {
|
|
|
|
text = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCkPjvF2tZ2lZtkXed6lBvaPUpsNrI5kHlCNEf4LyFtgFXHoUL8UD3Bz9Fn1S+SDkdBMw/SumjvUf7TEGqQqzmFbG7+nWdWg2L00VdN8Kp8W+kKPBByJrzjDUIGhIMt7obaZnlSAVO5Cdqc1Q6bA9POLjSHIBxSD3QUs2pjUCkciNcEtL93easuXnlMwoYa217n5sA8n+BZmOJAcmA/UxYvKsqYlpJxa44m8JgMTy+5L08i/zkx9/FwniOcKcLedxmjZfV8raitDy34LslT2nBNG4I+em7qhKhSScn/cfyPvARiK71pk/rTx9mxBEjcGAkp3+hiA3Nyms0h/qTUh8yGyhbOn8hiro34HEKswXDN1HRfseyyZ4TqOoIC07F53x4OliYA0B+QbvwOemTX2XAWHfU4xEYrIhR46o3Eu5ooOM9HZLLYzIzKjsj/rpuKalFZ+9IeT/PJ/DrbgOEBlJGTu4XucEYXSiIvWB7G9WXij7TXKYbsRAFho9jw+9UZWklFAh9dcUKlX9YxafxOrw9DhJK620hblHLY9wPPFCbZVXDGfqdtn+ncRReMAw6N3VYqxMgnxd+OC52SMsSUi9VaL26i2UvEBwNYuim8GDnVabu/ciQLHMgifBONuF9sKD58ee5nnKgtYLDy9zU86aHBU78Ijew+WhYitO7qejMHMQ==";
|
|
|
|
mode = "600";
|
|
|
|
user = "gitea";
|
|
|
|
};
|
|
|
|
|
2024-05-08 17:47:47 +00:00
|
|
|
services.nginx.virtualHosts."git.${config.pub-solar-os.networking.domain}" = {
|
2023-10-28 19:46:18 +00:00
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
|
|
|
|
locations."/user/login".extraConfig = ''
|
|
|
|
return 302 /user/oauth2/keycloak;
|
|
|
|
'';
|
|
|
|
|
2023-10-29 22:04:33 +00:00
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://127.0.0.1:3000";
|
|
|
|
extraConfig = ''
|
|
|
|
client_max_body_size 1G;
|
|
|
|
'';
|
|
|
|
};
|
2023-10-28 19:46:18 +00:00
|
|
|
};
|
|
|
|
|
2024-02-06 11:19:45 +00:00
|
|
|
users.users.gitea = {
|
|
|
|
home = "/var/lib/forgejo";
|
|
|
|
useDefaultShell = true;
|
|
|
|
group = "gitea";
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.gitea = { };
|
|
|
|
|
2024-04-05 13:35:47 +00:00
|
|
|
# Expose SSH port only for forgejo SSH
|
2024-04-05 16:39:43 +00:00
|
|
|
networking.firewall.interfaces.enp35s0.allowedTCPPorts = [ 2223 ];
|
2024-04-05 15:00:28 +00:00
|
|
|
networking.firewall.extraCommands = ''
|
|
|
|
iptables -t nat -i enp35s0 -I PREROUTING -p tcp --dport 22 -j REDIRECT --to-ports 2223
|
2024-04-05 18:55:00 +00:00
|
|
|
ip6tables -t nat -i enp35s0 -I PREROUTING -p tcp --dport 22 -j REDIRECT --to-ports 2223
|
2024-04-05 15:00:28 +00:00
|
|
|
'';
|
2024-04-05 13:35:47 +00:00
|
|
|
|
2024-02-06 11:19:45 +00:00
|
|
|
services.forgejo = {
|
2023-10-28 19:46:18 +00:00
|
|
|
enable = true;
|
2024-02-06 11:19:45 +00:00
|
|
|
user = "gitea";
|
|
|
|
group = "gitea";
|
2023-10-28 19:46:18 +00:00
|
|
|
database = {
|
|
|
|
type = "postgres";
|
|
|
|
passwordFile = config.age.secrets.forgejo-database-password.path;
|
2024-02-06 11:19:45 +00:00
|
|
|
name = "gitea";
|
|
|
|
user = "gitea";
|
2023-10-28 19:46:18 +00:00
|
|
|
};
|
|
|
|
stateDir = "/var/lib/forgejo";
|
|
|
|
lfs.enable = true;
|
|
|
|
mailerPasswordFile = config.age.secrets.forgejo-mailer-password.path;
|
|
|
|
settings = {
|
2024-02-07 18:02:04 +00:00
|
|
|
DEFAULT.APP_NAME = "pub.solar git server";
|
|
|
|
|
2023-10-28 19:46:18 +00:00
|
|
|
server = {
|
2024-05-08 17:47:47 +00:00
|
|
|
ROOT_URL = "https://git.${config.pub-solar-os.networking.domain}";
|
|
|
|
DOMAIN = "git.${config.pub-solar-os.networking.domain}";
|
2023-10-28 19:46:18 +00:00
|
|
|
HTTP_ADDR = "127.0.0.1";
|
|
|
|
HTTP_PORT = 3000;
|
2024-04-05 13:35:47 +00:00
|
|
|
START_SSH_SERVER = true;
|
2024-04-05 15:00:28 +00:00
|
|
|
SSH_LISTEN_PORT = 2223;
|
2024-04-05 17:14:10 +00:00
|
|
|
SSH_SERVER_HOST_KEYS = "${config.age.secrets."forgejo-ssh-private-key".path}";
|
2023-10-28 19:46:18 +00:00
|
|
|
};
|
2023-12-08 16:09:32 +00:00
|
|
|
|
2023-10-29 01:48:51 +00:00
|
|
|
log.LEVEL = "Warn";
|
2023-12-08 16:09:32 +00:00
|
|
|
|
2023-10-28 19:46:18 +00:00
|
|
|
mailer = {
|
|
|
|
ENABLED = true;
|
|
|
|
PROTOCOL = "smtps";
|
2023-12-05 17:23:04 +00:00
|
|
|
SMTP_ADDR = "mail.greenbaum.zone";
|
2023-10-28 19:46:18 +00:00
|
|
|
SMTP_PORT = 465;
|
|
|
|
FROM = ''"pub.solar git server" <forgejo@pub.solar>'';
|
|
|
|
USER = "admins@pub.solar";
|
|
|
|
};
|
2023-12-08 16:09:32 +00:00
|
|
|
|
2023-10-28 19:46:18 +00:00
|
|
|
"repository.signing" = {
|
|
|
|
SIGNING_KEY = "default";
|
|
|
|
MERGES = "always";
|
|
|
|
};
|
2023-12-08 16:09:32 +00:00
|
|
|
|
2023-10-28 19:46:18 +00:00
|
|
|
openid = {
|
|
|
|
ENABLE_OPENID_SIGNIN = true;
|
|
|
|
ENABLE_OPENID_SIGNUP = true;
|
|
|
|
};
|
2023-12-08 16:09:32 +00:00
|
|
|
|
2023-11-05 12:46:09 +00:00
|
|
|
service = {
|
|
|
|
# uncomment after initial deployment, first user is admin user
|
|
|
|
# required to setup SSO (oauth openid-connect, keycloak auth provider)
|
|
|
|
ALLOW_ONLY_EXTERNAL_REGISTRATION = true;
|
|
|
|
ENABLE_NOTIFY_MAIL = true;
|
|
|
|
DEFAULT_KEEP_EMAIL_PRIVATE = true;
|
|
|
|
};
|
2023-12-08 16:09:32 +00:00
|
|
|
|
2023-11-05 12:46:09 +00:00
|
|
|
session = {
|
2023-11-06 21:34:51 +00:00
|
|
|
PROVIDER = "db";
|
2023-11-05 12:46:09 +00:00
|
|
|
COOKIE_SECURE = lib.mkForce true;
|
|
|
|
};
|
2023-12-08 16:09:32 +00:00
|
|
|
|
|
|
|
# https://forgejo.org/docs/latest/admin/config-cheat-sheet/#webhook-webhook
|
|
|
|
webhook = {
|
2024-05-08 17:47:47 +00:00
|
|
|
ALLOWED_HOST_LIST = "loopback,external,*.${config.pub-solar-os.networking.domain}";
|
2023-12-08 16:09:32 +00:00
|
|
|
};
|
|
|
|
|
2023-10-29 22:52:33 +00:00
|
|
|
# See https://forgejo.org/docs/latest/admin/actions/
|
2023-12-08 16:09:32 +00:00
|
|
|
actions = {
|
|
|
|
ENABLED = true;
|
|
|
|
# In an actions workflow, when uses: does not specify an absolute URL,
|
|
|
|
# the value of DEFAULT_ACTIONS_URL is prepended to it.
|
|
|
|
DEFAULT_ACTIONS_URL = "https://code.forgejo.org";
|
|
|
|
};
|
2024-04-05 21:29:49 +00:00
|
|
|
|
|
|
|
# https://forgejo.org/docs/next/admin/recommendations/#securitylogin_remember_days
|
|
|
|
security = {
|
|
|
|
LOGIN_REMEMBER_DAYS = 365;
|
|
|
|
};
|
|
|
|
|
|
|
|
# https://forgejo.org/docs/next/admin/config-cheat-sheet/#indexer-indexer
|
|
|
|
indexer = {
|
|
|
|
REPO_INDEXER_ENABLED = true;
|
|
|
|
REPO_INDEXER_PATH = "indexers/repos.bleve";
|
|
|
|
MAX_FILE_SIZE = 1048576;
|
|
|
|
REPO_INDEXER_EXCLUDE = "resources/bin/**";
|
|
|
|
};
|
2023-10-28 19:46:18 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# See: https://docs.gitea.io/en-us/signing/#installing-and-generating-a-gpg-key-for-gitea
|
|
|
|
# Required for gitea server side gpg signatures
|
|
|
|
# configured/setup manually in:
|
|
|
|
# /var/lib/gitea/data/home/.gitconfig
|
|
|
|
# /var/lib/gitea/data/home/.gnupg/
|
|
|
|
# sudo su gitea
|
|
|
|
# export GNUPGHOME=/var/lib/gitea/data/home/.gnupg
|
|
|
|
# gpg --quick-gen-key 'pub.solar gitea <gitea@pub.solar>' ed25519
|
|
|
|
# TODO: implement declarative GPG key generation and
|
|
|
|
# gitea gitconfig
|
|
|
|
programs.gnupg.agent = {
|
|
|
|
enable = true;
|
|
|
|
pinentryFlavor = "curses";
|
|
|
|
};
|
|
|
|
# Required to make gpg work without a graphical environment?
|
|
|
|
# otherwise generating a new gpg key fails with this error:
|
|
|
|
# gpg: agent_genkey failed: No pinentry
|
|
|
|
# see: https://github.com/NixOS/nixpkgs/issues/97861#issuecomment-827951675
|
|
|
|
environment.variables = {
|
|
|
|
GPG_TTY = "$(tty)";
|
|
|
|
};
|
2023-11-05 21:54:09 +00:00
|
|
|
|
2023-11-18 21:28:12 +00:00
|
|
|
services.restic.backups.forgejo-droppie = {
|
2023-11-05 21:54:09 +00:00
|
|
|
paths = [
|
|
|
|
"/var/lib/forgejo"
|
|
|
|
"/tmp/forgejo-backup.sql"
|
|
|
|
];
|
2023-11-05 22:47:06 +00:00
|
|
|
timerConfig = {
|
|
|
|
OnCalendar = "*-*-* 02:00:00 Etc/UTC";
|
|
|
|
# droppie will be offline if nachtigall misses the timer
|
|
|
|
Persistent = false;
|
|
|
|
};
|
|
|
|
initialize = true;
|
|
|
|
passwordFile = config.age.secrets."restic-repo-droppie".path;
|
2023-11-06 21:58:48 +00:00
|
|
|
repository = "sftp:yule@droppie.b12f.io:/media/internal/pub.solar";
|
2023-11-05 21:54:09 +00:00
|
|
|
backupPrepareCommand = ''
|
2023-11-06 21:22:36 +00:00
|
|
|
${pkgs.sudo}/bin/sudo -u postgres ${pkgs.postgresql}/bin/pg_dump -d gitea > /tmp/forgejo-backup.sql
|
2023-11-05 21:54:09 +00:00
|
|
|
'';
|
|
|
|
backupCleanupCommand = ''
|
|
|
|
rm /tmp/forgejo-backup.sql
|
|
|
|
'';
|
2024-04-22 18:06:49 +00:00
|
|
|
pruneOpts = [
|
|
|
|
"--keep-daily 7"
|
|
|
|
"--keep-weekly 4"
|
|
|
|
"--keep-monthly 3"
|
|
|
|
];
|
2023-11-05 21:54:09 +00:00
|
|
|
};
|
2023-11-18 21:28:12 +00:00
|
|
|
|
|
|
|
services.restic.backups.forgejo-storagebox = {
|
|
|
|
paths = [
|
|
|
|
"/var/lib/forgejo"
|
|
|
|
"/tmp/forgejo-backup.sql"
|
|
|
|
];
|
|
|
|
timerConfig = {
|
2024-05-15 19:00:41 +00:00
|
|
|
OnCalendar = "*-*-* 00:00:00 Etc/UTC";
|
2023-11-18 21:28:12 +00:00
|
|
|
};
|
|
|
|
initialize = true;
|
|
|
|
passwordFile = config.age.secrets."restic-repo-storagebox".path;
|
|
|
|
repository = "sftp:u377325@u377325.your-storagebox.de:/backups";
|
|
|
|
backupPrepareCommand = ''
|
|
|
|
${pkgs.sudo}/bin/sudo -u postgres ${pkgs.postgresql}/bin/pg_dump -d gitea > /tmp/forgejo-backup.sql
|
|
|
|
'';
|
|
|
|
backupCleanupCommand = ''
|
|
|
|
rm /tmp/forgejo-backup.sql
|
|
|
|
'';
|
2024-04-22 18:06:49 +00:00
|
|
|
pruneOpts = [
|
|
|
|
"--keep-daily 7"
|
|
|
|
"--keep-weekly 4"
|
|
|
|
"--keep-monthly 3"
|
|
|
|
];
|
2023-11-18 21:28:12 +00:00
|
|
|
};
|
2023-10-28 19:46:18 +00:00
|
|
|
}
|