2023-08-31 01:55:45 +03:00
|
|
|
{ cluster, config, depot, lib, pkgs, ... }:
|
2023-07-21 02:26:26 +03:00
|
|
|
|
|
|
|
let
|
2023-08-31 01:55:45 +03:00
|
|
|
inherit (depot.lib.meta) domain;
|
2024-07-08 17:08:39 +03:00
|
|
|
inherit (cluster.config.services.forge) secrets;
|
2023-07-21 02:26:26 +03:00
|
|
|
|
|
|
|
patroni = cluster.config.links.patroni-pg-access;
|
|
|
|
|
|
|
|
host = "forge.${domain}";
|
|
|
|
|
2024-07-04 05:25:56 +03:00
|
|
|
link = cluster.config.hostLinks.${config.networking.hostName}.forge;
|
2023-07-21 02:26:26 +03:00
|
|
|
|
2024-06-04 19:57:24 +03:00
|
|
|
exe = lib.getExe config.services.forgejo.package;
|
2023-07-21 02:26:26 +03:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2024-06-04 20:54:44 +03:00
|
|
|
system.ascensions.forgejo = {
|
2024-06-05 02:51:28 +03:00
|
|
|
requiredBy = [ "forgejo.service" ];
|
|
|
|
before = [ "forgejo.service" ];
|
|
|
|
incantations = i: [
|
|
|
|
(i.execShell "chown -R forgejo:forgejo /srv/storage/private/forge")
|
2024-07-04 01:26:07 +03:00
|
|
|
(i.execShell "rm -rf /srv/storage/private/forge/data/{attachments,lfs,avatars,repo-avatars,repo-archive,packages,actions_log,actions_artifacts}")
|
2024-06-05 02:51:28 +03:00
|
|
|
];
|
2024-06-04 20:54:44 +03:00
|
|
|
};
|
|
|
|
|
2024-07-11 00:18:52 +03:00
|
|
|
services.locksmith.waitForSecrets.forgejo = [
|
|
|
|
"garage-forgejo-id"
|
|
|
|
"garage-forgejo-secret"
|
|
|
|
];
|
|
|
|
|
2024-06-04 19:57:24 +03:00
|
|
|
services.forgejo = {
|
2023-07-21 02:26:26 +03:00
|
|
|
enable = true;
|
|
|
|
package = depot.packages.forgejo;
|
|
|
|
stateDir = "/srv/storage/private/forge";
|
|
|
|
database = {
|
|
|
|
createDatabase = false;
|
|
|
|
type = "postgres";
|
|
|
|
host = patroni.ipv4;
|
|
|
|
inherit (patroni) port;
|
|
|
|
name = "forge";
|
|
|
|
user = "forge";
|
2024-07-08 17:08:39 +03:00
|
|
|
passwordFile = secrets.dbCredentials.path;
|
2023-07-21 02:26:26 +03:00
|
|
|
};
|
|
|
|
settings = {
|
2024-06-04 20:11:38 +03:00
|
|
|
DEFAULT = {
|
|
|
|
APP_NAME = "The Forge";
|
|
|
|
};
|
2023-07-21 02:26:26 +03:00
|
|
|
server = {
|
|
|
|
DOMAIN = host;
|
|
|
|
ROOT_URL = "https://${host}/";
|
|
|
|
PROTOCOL = link.protocol;
|
|
|
|
HTTP_ADDR = link.ipv4;
|
|
|
|
HTTP_PORT = link.port;
|
|
|
|
};
|
|
|
|
oauth2_client = {
|
|
|
|
REGISTER_EMAIL_CONFIRM = false;
|
|
|
|
ENABLE_AUTO_REGISTRATION = true;
|
|
|
|
ACCOUNT_LINKING = "auto";
|
|
|
|
UPDATE_AVATAR = true;
|
|
|
|
};
|
|
|
|
session.COOKIE_SECURE = true;
|
|
|
|
service = {
|
|
|
|
DISABLE_REGISTRATION = false;
|
|
|
|
ALLOW_ONLY_INTERNAL_REGISTRATION = false;
|
|
|
|
ALLOW_ONLY_EXTERNAL_REGISTRATION = true;
|
|
|
|
};
|
2024-07-04 01:26:07 +03:00
|
|
|
storage = {
|
|
|
|
STORAGE_TYPE = "minio";
|
|
|
|
MINIO_ENDPOINT = cluster.config.links.garageS3.hostname;
|
|
|
|
MINIO_BUCKET = "forgejo";
|
|
|
|
MINIO_USE_SSL = true;
|
|
|
|
MINIO_BUCKET_LOOKUP = "path";
|
|
|
|
};
|
2024-07-09 21:40:55 +03:00
|
|
|
log."logger.xorm.MODE" = "";
|
2023-07-21 02:26:26 +03:00
|
|
|
# enabling this will leak secrets to the log
|
|
|
|
database.LOG_SQL = false;
|
|
|
|
};
|
2024-07-04 01:26:07 +03:00
|
|
|
secrets = {
|
|
|
|
storage = {
|
2024-07-11 00:18:52 +03:00
|
|
|
MINIO_ACCESS_KEY_ID = "/run/locksmith/garage-forgejo-id";
|
|
|
|
MINIO_SECRET_ACCESS_KEY = "/run/locksmith/garage-forgejo-secret";
|
2024-07-04 01:26:07 +03:00
|
|
|
};
|
|
|
|
};
|
2023-07-21 02:26:26 +03:00
|
|
|
};
|
|
|
|
|
2024-06-04 19:57:24 +03:00
|
|
|
systemd.services.forgejo.preStart = let
|
2023-07-21 02:26:26 +03:00
|
|
|
providerName = "PrivateVoidAccount";
|
|
|
|
args = lib.escapeShellArgs [
|
|
|
|
"--name" providerName
|
|
|
|
"--provider" "openidConnect"
|
|
|
|
"--key" "net.privatevoid.forge1"
|
|
|
|
"--auto-discover-url" "https://login.${domain}/auth/realms/master/.well-known/openid-configuration"
|
|
|
|
"--group-claim-name" "groups"
|
|
|
|
"--admin-group" "/forge_admins@${domain}"
|
|
|
|
];
|
|
|
|
in lib.mkAfter /*bash*/ ''
|
|
|
|
providerId="$(${exe} admin auth list | ${pkgs.gnugrep}/bin/grep -w '${providerName}' | cut -f1)"
|
|
|
|
if [[ -z "$providerId" ]]; then
|
2024-07-08 17:08:39 +03:00
|
|
|
FORGEJO_ADMIN_OAUTH2_SECRET="$(< ${secrets.oidcSecret.path})" ${exe} admin auth add-oauth ${args}
|
2023-07-21 02:26:26 +03:00
|
|
|
else
|
2024-07-08 17:08:39 +03:00
|
|
|
FORGEJO_ADMIN_OAUTH2_SECRET="$(< ${secrets.oidcSecret.path})" ${exe} admin auth update-oauth --id "$providerId" ${args}
|
2023-07-21 02:26:26 +03:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
}
|