more generic approach, but stills limited to vogon, for the forgejo profile

This commit is contained in:
Sic mundus creatus est 2025-07-01 22:26:25 +02:00
parent ea4d89eedc
commit 873479d893
2 changed files with 46 additions and 23 deletions

View file

@ -7,8 +7,21 @@ let
domain = "federez.net"; domain = "federez.net";
fqdn = "git.${domain}"; fqdn = "git.${domain}";
sys-ip = "193.54.193.164"; hasValidLastOctet =
git-ip = "193.54.193.165"; config ? vogon.networking.last-octet &&
builtins.length config.vogon.networking.last-octet >= 2;
lastOctetValues =
if hasValidLastOctet
then config.vogon.networking.last-octet
else abort ''Forgejo can only be deploy on vogon for now,
and it requires two public ip address, the first one
for ssh access from wan, and the second for the
forgejo dedicated ssh server'';
sys-ip = "193.54.193.${toString (builtins.elemAt lastOctetValues 0)}";
git-ip = "193.54.193.${toString (builtins.elemAt lastOctetValues 1)}";
in in
{ {
age.secrets = lib.mapAttrs age.secrets = lib.mapAttrs
@ -24,13 +37,7 @@ in
postgresqlDatabases = [ cfg.database.name ]; postgresqlDatabases = [ cfg.database.name ];
}; };
services.openssh = { services.openssh.startWhenNeeded = false;
listenAddresses = [{
addr = "${sys-ip}";
port = 22;
}];
startWhenNeeded = false;
};
services.forgejo = { services.forgejo = {
enable = true; enable = true;
@ -98,7 +105,7 @@ in
user = "wizard"; user = "wizard";
in '' in ''
# || true -> avoid systemd to crash on that command if user already exist by forcing a 0 return value # || true -> avoid systemd to crash on that command if user already exist by forcing a 0 return value
${adminCmd} create --admin --email "root@localhost" --username ${user} --password "$(tr -d '\n' < ${pwd})" || true ${adminCmd} create --admin --email "admin@federez.net" --username ${user} --password "$(tr -d '\n' < ${pwd})" || true
${adminCmd} change-password --username ${user} --password "$(tr -d '\n' < ${pwd})" || true ${adminCmd} change-password --username ${user} --password "$(tr -d '\n' < ${pwd})" || true
''; '';
@ -115,7 +122,7 @@ in
"git.federez.net" = { "git.federez.net" = {
enableACME = true; enableACME = true;
forceSSL = true; forceSSL = true;
locations."/".proxyPass = "http://localhost:3000"; locations."/".proxyPass = "http://localhost:${toString cfg.settings.server.HTTP_PORT}";
extraConfig = '' extraConfig = ''
client_max_body_size 1G; client_max_body_size 1G;
''; '';

View file

@ -1,4 +1,4 @@
{ config, lib, ... }: { config, lib, network, ... }:
let let
inherit (lib) mkOption types; inherit (lib) mkOption types;
@ -17,16 +17,27 @@ in
}; };
wan-mac = mkOption { wan-mac = mkOption {
type = types.str; type = types.str;
description = ''' description = ''
Adresse MAC de l'interface réseau WAN Adresse MAC de l'interface réseau WAN
qui portera l'IPv4 interne. qui portera l'IPv4 interne.
''; '';
example = "BC:24:11:B7:AE:80"; example = "BC:24:11:B7:AE:80";
}; };
ssh-octets = mkOption {
type = types.listOf (types.ints.between 161 174);
default = [ (builtins.head cfg.networking.last-octet) ];
defaultText = "[ (first element of last-octet) ]";
description = ''
Liste des octets à utiliser pour la configuration SSH.
Par défaut, utilise le premier élément de last-octet.
'';
example = [ 163 165 ];
};
}; };
}; };
config.systemd.network = { config = {
systemd.network = {
links."10-wan" = { links."10-wan" = {
matchConfig.MACAddress = cfg.networking.wan-mac; matchConfig.MACAddress = cfg.networking.wan-mac;
linkConfig.Name = "wan"; linkConfig.Name = "wan";
@ -38,4 +49,9 @@ in
linkConfig.RequiredForOnline = "routable"; linkConfig.RequiredForOnline = "routable";
}; };
}; };
services.openssh.listenAddresses = [
{ addr = network.infra.nodes.${config.networking.hostName}.ipv4; port = 22; }
{ addr = network.infra.nodes.${config.networking.hostName}.ipv6; port = 22; }
] ++ map (octet: { addr = "193.54.193.${toString octet}"; port = 22; }) cfg.networking.ssh-octets;
};
} }