153 current 2025-10-09 12:27:20 25.05.20251006.20c4598 6.12.50 *

This commit is contained in:
2025-10-09 12:36:24 -05:00
parent 126754154d
commit 7bd74aea43
6 changed files with 49 additions and 328 deletions

View File

@@ -1,59 +1,71 @@
{ pkgs, config, lib, ... }:
let
cfg = config.modules.services.gitea;
ids = 2703;
default_port = 3000;
data_dir = "/var/lib/gitea";
service = "gitea";
cfg = config.modules.services.${service};
sec = config.sops.secrets;
homelab = config.modules.homelab;
in
{
options.modules.services.gitea = {
enable = lib.mkEnableOption "enables gitea";
options.modules.services.${service} = {
enable = lib.mkEnableOption "enables ${service}";
# set port options
port = lib.mkOption {
type = lib.types.int;
default = 7703;
description = "set port for gitea (default: ${toString default_port}";
description = "set port for ${service} (default: ${toString cfg.port}";
};
# set ssh port
ssh_port = lib.mkOption {
type = lib.types.int;
default = 7567;
description = "set port for gitea (default: 2222";
description = "set port for ${service} (default: ${toString cfg.port}";
};
url = lib.mkOption {
type = lib.types.str;
default = "${service}.${homelab.base_domain}";
description = "set domain for ${service}";
};
data_dir = lib.mkOption {
type = lib.types.str;
default = "/var/lib/${service}";
description = "set data directory for ${service}";
};
ids = lib.mkOption {
type = lib.types.int;
default = cfg.port;
description = "set uid and pid of ${service} user (matches port by default)";
};
backup = lib.mkOption {
type = lib.types.bool;
default = true;
description = "enable backups for gitea";
description = "enable backups for ${service}";
};
};
config = lib.mkIf cfg.enable {
# declare gitea group
users.groups.gitea = { gid = ids; };
# declare ${service} group
users.groups.${service} = { gid = lib.mkForce cfg.ids; };
# declare gitea user
users.users.gitea = {
description = lib.mkForce "gitea server user";
uid = ids;
# declare ${service} user
users.users.${service} = {
description = "${service} server user";
uid = lib.mkForce cfg.ids;
isSystemUser = true;
shell = pkgs.bash;
home = "/var/lib/gitea";
shell = pkgs.bash;
home = cfg.data_dir;
createHome = true;
group = "gitea";
group = "${service}";
extraGroups = [];
};
# enable the gitea service
# declare the gitea service
services.gitea = {
enable = true;
user = "gitea";
group = "gitea";
stateDir = data_dir;
stateDir = cfg.data_dir;
appName = "gitea";
settings = {
server = {
@@ -69,43 +81,41 @@ in
passwordFile = "${toString config.sops.secrets."gitea_database_password".path}";
};
};
# override umask to make permissions work out
systemd.services.gitea.serviceConfig = { UMask = lib.mkForce "0007"; };
systemd.services.${service}.serviceConfig = {
UMask = lib.mkForce "0007";
};
# open firewall
networking.firewall.allowedTCPPorts = [ cfg.port cfg.ssh_port ];
# internal reverse proxy entry
services.nginx.virtualHosts."git.snowbelle.lan" = {
enableACME = false;
services.nginx.virtualHosts."${cfg.url}" = {
forceSSL = true;
sslCertificate = config.sops.secrets."ssl_blakedheld_crt".path;
sslCertificateKey = config.sops.secrets."ssl_blakedheld_key".path;
sslCertificate = sec."ssl_blakedheld_crt".path;
sslCertificateKey = sec."ssl_blakedheld_key".path;
locations."/" = {
proxyPass = "http://127.0.0.1:${toString cfg.port}";
};
};
# external reverse proxy entry
services.nginx.virtualHosts."git.blakedheld.xyz" = {
enableACME = true;
useACME = true;
forceSSL = true;
# sslCertificate = config.sops.secrets."ssl_blakedheld_crt".path;
# sslCertificateKey = config.sops.secrets."ssl_blakedheld_key".path;
locations."/" = {
proxyPass = "http://127.0.0.1:${toString cfg.port}";
};
};
sops.secrets = {
"gitea_database_password" = {
owner = "gitea";
group = "gitea";
# neededForUsers = true;
"${service}_database_password" = {
owner = "${service}";
group = "${service}";
};
};
# add to backups
modules.system.backups.paths = lib.mkIf cfg.backup [ data_dir ];
modules.system.backups.paths = lib.mkIf cfg.backup [ cfg.data_dir ];
};
}