summaryrefslogtreecommitdiff
path: root/modules/root/services/gitea.nix
blob: 32c56db7b17881f9bd4c434de51ba08028473bc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{ lib, pkgs, config, userDetails, ... }:
let
	cfg = config.gitea;
in {
	options = {
		gitea = {
			enable = lib.mkEnableOption "enables gitea service";
			hostAddress = lib.mkOption {
				type = lib.types.str;
				description = "hostAddress for the container";
				default = "10.0.1.1";
			};
			localAddress = lib.mkOption {
				type = lib.types.str;
				description = "localAddress for the container";
				default = "10.0.1.3";
			};
		};
	};

	config = lib.mkIf cfg.enable {
		containers.gitea = {
			autoStart = true;
			privateNetwork = true;
			hostAddress  = cfg.hostAddress;
			localAddress = cfg.localAddress;

			config = { lib, config, ... }: {
				# Enable gitea service
				services.gitea = {
					enable = true;
					user = "git";  # So ssh cloning uses git@gitea
					settings = {
						server = {
							HTTP_PORT = 3000;  # Can't set as 80 without root permissions, use 3000 instead
						};
					};
				};

				# Networking, etc.
				# Redirect 80 to 3000
				networking.nftables = {
					enable = true;
					ruleset = ''
						table ip nat {
							chain prerouting {
								type nat hook prerouting priority 0;
								tcp dport 80 redirect to :3000
							}
						}
					'';
				};
				networking.firewall.allowedTCPPorts = [ 3000 80 22 ];  # Still need to forward 3000 for nftables rule to work
				networking.hostName = "gitea";

				system.stateVersion = "25.05";
			};
		};
	};
}