move forgejo to host

This commit is contained in:
chaos 2024-07-20 12:58:45 +01:00
parent 657b52b580
commit b80228d8af
No known key found for this signature in database
7 changed files with 41 additions and 139 deletions

View file

@ -1,72 +0,0 @@
{
self,
hostPath,
tree,
inputs,
pkgs,
config,
...
}: let
containerName = "forgejo";
containerAddresses = import "${hostPath}/data/containerAddresses.nix";
hostIP = containerAddresses.host;
containerIP = containerAddresses.containers.${containerName};
pathInContainer = path: "/var/lib/nixos-containers/${containerName}" + path;
in {
containers.forgejo = {
autoStart = true;
privateNetwork = true;
hostAddress = hostIP;
localAddress = containerIP;
specialArgs = {
inherit inputs;
inherit tree;
inherit self;
inherit hostPath;
};
config = {...}: {
nixpkgs.pkgs = pkgs;
imports = with tree;
[
presets.nixos.containerBase
./secrets.nix
]
++ (with hosts.hetzner-arm.containers.forgejo.profiles; [
forgejo
restic
]);
networking.firewall.allowedTCPPorts = [2222];
home-manager.users.root.home.stateVersion = "24.05";
system.stateVersion = "24.05";
};
};
networking = {
nat.forwardPorts = [
{
sourcePort = 2222;
destination = "${containerIP}\:2222";
}
];
firewall.allowedTCPPorts = [2222];
};
services.nginx = {
enable = true;
virtualHosts."forgejo.owo.monster" = {
enableACME = true;
forceSSL = true;
locations."/".proxyPass = "http://unix:${pathInContainer "/var/sockets/forgejo.sock"}";
};
};
}

View file

@ -1,23 +0,0 @@
{
self,
config,
...
}: let
backupSchedules = import "${self}/data/backupSchedules.nix";
inherit (config.services.secrets) secrets;
in {
services.restic.backups.forgejo = {
user = "root";
paths = [
"/var/lib/forgejo"
];
repository = "s3:s3.eu-central-003.backblazeb2.com/Chaos-Backups/Restic/Forgejo";
passwordFile = "${secrets.restic_password.path}";
environmentFile = "${secrets.restic_env.path}";
createWrapper = true;
pruneOpts = ["--keep-last 50"];
timerConfig = backupSchedules.restic.high;
};
}

View file

@ -1,35 +0,0 @@
{...}: {
services.secrets = {
enable = true;
vaultLogin = {
enable = true;
loginUsername = "hetzner-arm-container-forgejo";
};
requiredVaultPaths = [
"api-keys/data/backblaze/Chaos-Backups"
"private-public-keys/data/restic/Forgejo"
];
secrets = {
vault_password = {
manual = true;
};
restic_password = {
fetchScript = ''
simple_get "/private-public-keys/restic/Forgejo" .password > "$secretFile"
'';
};
restic_env = {
fetchScript = ''
cat << EOF > "$secretFile"
AWS_ACCESS_KEY_ID=$(simple_get "/api-keys/backblaze/Chaos-Backups" .keyID)
AWS_SECRET_ACCESS_KEY=$(simple_get "/api-keys/backblaze/Chaos-Backups" .applicationKey)
EOF
'';
};
};
};
}

View file

@ -22,7 +22,6 @@ in {
++ (forEach [ ++ (forEach [
"storage" "storage"
"mail" "mail"
"forgejo"
"caldav" "caldav"
"jellyfin" "jellyfin"
#"grocy" #"grocy"
@ -32,6 +31,7 @@ in {
++ (with hosts.hetzner-arm.profiles; [ ++ (with hosts.hetzner-arm.profiles; [
staticSites staticSites
gotosocial gotosocial
forgejo
restic restic
]); ]);

View file

@ -11,7 +11,7 @@
DOMAIN = "forgejo.owo.monster"; DOMAIN = "forgejo.owo.monster";
ROOT_URL = "https://${DOMAIN}"; ROOT_URL = "https://${DOMAIN}";
# Can't access /run out of container # Can't access /run out of container
HTTP_ADDR = "/var/sockets/forgejo.sock"; HTTP_ADDR = "/var/sockets/forgejo/forgejo.sock";
PROTOCOL = "http+unix"; PROTOCOL = "http+unix";
START_SSH_SERVER = true; START_SSH_SERVER = true;
SSH_PORT = 2222; SSH_PORT = 2222;
@ -65,10 +65,20 @@
]; ];
systemd.services.forgejo.serviceConfig.ReadWritePaths = [ systemd.services.forgejo.serviceConfig.ReadWritePaths = [
"/var/sockets" "/var/sockets/forgejo"
]; ];
systemd.tmpfiles.rules = [ systemd.tmpfiles.rules = [
"d /var/sockets - forgejo forgejo" "d /var/sockets - root root"
"d /var/sockets/forgejo - forgejo forgejo"
]; ];
services.nginx = {
enable = true;
virtualHosts."forgejo.owo.monster" = {
enableACME = true;
forceSSL = true;
locations."/".proxyPass = "http://unix:/var/sockets/forgejo/forgejo.sock";
};
};
} }

View file

@ -8,6 +8,8 @@
inherit (lib.lists) forEach; inherit (lib.lists) forEach;
inherit (lib.strings) concatStringsSep; inherit (lib.strings) concatStringsSep;
inherit (builtins) attrNames;
inherit (config.services.secrets) secrets; inherit (config.services.secrets) secrets;
backupSchedules = import "${self}/data/backupSchedules.nix"; backupSchedules = import "${self}/data/backupSchedules.nix";
@ -16,11 +18,9 @@ in {
environment.systemPackages = [ environment.systemPackages = [
# TODO: add ones in container too # TODO: add ones in container too
(pkgs.writeShellScriptBin "restic-all" '' (pkgs.writeShellScriptBin "restic-all" ''
${concatStringsSep "\n" (forEach [ ${concatStringsSep "\n" (forEach (attrNames config.services.restic.backups) (
"social" name: "restic-${name} $@"
] ( ))}
name: "restic-${name} $@"
))}
'') '')
]; ];
@ -69,5 +69,19 @@ in {
'') '')
}/bin/backupCleanupCommand"; }/bin/backupCleanupCommand";
}; };
forgejo = {
user = "root";
paths = [
"/var/lib/forgejo"
];
repository = "${repoRoot}/Forgejo";
environmentFile = secrets.restic_backups_env.path;
passwordFile = secrets.restic_password_forgejo.path;
createWrapper = true;
pruneOpts = ["--keep-last 50"];
timerConfig = backupSchedules.restic.high;
};
}; };
} }

View file

@ -15,6 +15,8 @@
"private-public-keys/data/restic/Social" "private-public-keys/data/restic/Social"
"api-keys/data/chaos_mail/gotosocial" "api-keys/data/chaos_mail/gotosocial"
"private-public-keys/data/restic/Forgejo"
]; ];
secrets = { secrets = {
@ -72,6 +74,12 @@
echo "GTS_SMTP_PASSWORD=$smtp_password" > "$secretFile" echo "GTS_SMTP_PASSWORD=$smtp_password" > "$secretFile"
''; '';
}; };
restic_password_forgejo = {
fetchScript = ''
simple_get "/private-public-keys/restic/Forgejo" .password > "$secretFile"
'';
};
}; };
}; };
} }