Created a helper to create the container configurations. Updated all containers files to use it.

This commit is contained in:
Raphaël Numbus
2026-02-20 10:23:24 +01:00
parent 3b130bc2e9
commit c90169f242
10 changed files with 706 additions and 916 deletions
+65 -107
View File
@@ -1,119 +1,77 @@
{ config, pkgs, ... }:
{ config, pkgs, lib, ... }:
with lib;
let
containerName = "gitea";
composeFile = "podman/gitea/compose.yaml";
configDir = "/mnt/config/gitea";
dataDir = "gitea_data";
helper = import ./lib.nix { inherit config pkgs lib; };
cfg = config.numbus.services.gitea;
in
{
config = {
environment.etc."${compose_file}".text =
/*
yaml
*/
''
services:
gitea-server:
image: docker.gitea.com/gitea:latest-rootless
container_name: gitea-server
hostname: gitea-server
networks:
gitea_frontend:
gitea_backend:
ports:
- "3000:3000/tcp" #http
volumes:
- gitea_data:/var/lib/gitea
- ${configDir}:/etc/gitea
- /etc/localtime:/etc/localtime:ro
environment:
- GITEA__database__DB_TYPE=postgres
- GITEA__database__HOST=$POSTGRES_HOST:$POSTGRES_PORT
- GITEA__database__NAME=$DB_NAME
- GITEA__database__USER=$DB_USERNAME
- GITEA__database__PASSWD=$DB_PASSWORD
- GITEA__server__SSH_PORT=2424
- GITEA__server__ROOT_URL=gitea.$DOMAIN_NAME
depends_on:
- gitea-database
restart: unless-stopped
gitea-database:
image: docker.io/library/postgres:14
container_name: gitea-database
hostname: gitea-database
networks:
gitea_backend:
volumes:
- gitea_database:/var/lib/postgresql/data
environment:
- POSTGRES_USER=$DB_USERNAME
- POSTGRES_PASSWORD=$DB_PASSWORD
- POSTGRES_DB=$DB_NAME
restart: unless-stopped
volumes:
gitea_data:
gitea_database:
helper.mkPodmanService {
name = "gitea";
description = "Gitea, your own self-hosted git platform";
defaultPort = "3000";
pod = "gitea";
dependencies = [ "traefik.service" "${config.numbus.services.dns}.service" ];
composeText = ''
services:
gitea-server:
image: docker.gitea.com/gitea:latest-rootless
container_name: gitea-server
hostname: gitea-server
networks:
gitea_frontend:
name: gitea_frontend
driver: bridge
ipam:
config:
- subnet: "10.89.3.0/24"
gateway: "10.89.3.254"
gitea_backend:
name: gitea_backend
driver: bridge
ipam:
config:
- subnet: "10.89.4.0/24"
gateway: "10.89.4.254"
'';
ports:
- "${cfg.port}:3000/tcp"
volumes:
- ${cfg.dataDir}:/var/lib/gitea
- ${cfg.configDir}:/etc/gitea
- /etc/localtime:/etc/localtime:ro
environment:
- GITEA__database__DB_TYPE=postgres
- GITEA__database__HOST=$POSTGRES_HOST:$POSTGRES_PORT
- GITEA__database__NAME=$DB_NAME
- GITEA__database__USER=$DB_USERNAME
- GITEA__database__PASSWD=$DB_PASSWORD
- GITEA__server__SSH_PORT=2424
- GITEA__server__ROOT_URL=${cfg.subdomain}.${config.numbus.services.domain}
depends_on:
- gitea-database
restart: unless-stopped
systemd.services."${container_name}" = {
description = "Podman container : ${container_name}";
after = [ "network.target" "traefik.service" "pi-hole.service" ];
requires = [ "traefik.service" ];
wantedBy = [ "multi-user.target" ];
path = [ pkgs.podman pkgs.coreutils ];
gitea-database:
image: docker.io/library/postgres:14
container_name: gitea-database
hostname: gitea-database
networks:
gitea_backend:
volumes:
- gitea_database:/var/lib/postgresql/data
environment:
- POSTGRES_USER=$DB_USERNAME
- POSTGRES_PASSWORD=$DB_PASSWORD
- POSTGRES_DB=$DB_NAME
restart: unless-stopped
serviceConfig = {
User = "numbus-admin";
Environment = [ "XDG_RUNTIME_DIR=/run/user/1000" ];
Type = "exec";
TimeoutStartSec = "900";
ExecStartPre = [
"${pkgs.bash}/bin/bash -c 'sleep $((RANDOM % 400))'"
"-${pkgs.podman-compose}/bin/podman-compose -f /etc/${compose_file} pull"
];
ExecStart = "${pkgs.podman-compose}/bin/podman-compose -f /etc/${compose_file} up --remove-orphans";
ExecStop = "${pkgs.podman-compose}/bin/podman-compose -f /etc/${compose_file} down";
Restart = "on-failure";
RestartSec = "5m";
StartLimitBurst = "3";
};
};
volumes:
gitea_database:
systemd.services."update-${container_name}" = {
description = "Update ${container_name} container";
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.systemd}/bin/systemctl restart ${container_name}.service";
};
};
systemd.timers."update-${container_name}" = {
timerConfig = {
OnCalendar = "02:00";
RandomizedDelaySec = "60m";
Unit = "update-${container_name}.service";
};
wantedBy = [ "timers.target" ];
};
};
networks:
gitea_frontend:
name: gitea_frontend
driver: bridge
ipam:
config:
- subnet: "10.89.3.0/24"
gateway: "10.89.3.254"
gitea_backend:
name: gitea_backend
driver: bridge
ipam:
config:
- subnet: "10.89.4.0/24"
gateway: "10.89.4.254"
'';
}