-
Notifications
You must be signed in to change notification settings - Fork 1
/
gitea.nix
141 lines (129 loc) · 4.16 KB
/
gitea.nix
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
{ pkgs, config, lib, ... }:
with lib;
let
cfg = config.eilean;
domain = config.networking.domain;
subdomain = "git.${domain}";
in {
options.eilean.gitea = {
enable = mkEnableOption "gitea";
sshPort = mkOption {
type = types.int;
default = 3001;
};
databasePasswordFile = mkOption {
type = types.nullOr types.path;
default = null;
};
};
config = mkIf cfg.gitea.enable {
security.acme-eon.nginxCerts = [ subdomain ];
services.nginx = {
enable = true;
recommendedProxySettings = true;
virtualHosts."${subdomain}" = {
enableACME = lib.mkIf (!cfg.acme-eon) true;
forceSSL = true;
locations."/" = {
proxyPass = "http://localhost:${
builtins.toString config.services.gitea.settings.server.HTTP_PORT
}/";
};
};
};
users.users.git = {
description = "Git Service";
home = config.services.gitea.stateDir;
useDefaultShell = true;
group = "gitea";
isSystemUser = true;
};
services.gitea = {
enable = true;
user = "git";
appName = "git | ${domain}";
mailerPasswordFile = cfg.mailserver.systemAccountPasswordFile;
settings = {
server = {
ROOT_URL = "https://${subdomain}/";
DOMAIN = subdomain;
};
mailer = {
ENABLED = true;
FROM = "git@${domain}";
MAILER_TYPE = "smtp";
HOST = "mail.${domain}:465";
USER = "system@${domain}";
IS_TLS_ENABLED = true;
};
repository.DEFAULT_BRANCH = "main";
service.DISABLE_REGISTRATION = true;
#server.HTTP_PORT = 3000;
};
database = {
type = "postgres";
passwordFile = cfg.gitea.databasePasswordFile;
user = "git";
name = "git";
#createDatabase = true;
#socket = "/run/postgresql";
};
#stateDir = "/var/lib/gitea";
};
# https://github.com/NixOS/nixpkgs/issues/103446
systemd.services.gitea.serviceConfig = {
ReadWritePaths = [ "/var/lib/postfix/queue/maildrop" ];
NoNewPrivileges = mkForce false;
PrivateDevices = mkForce false;
PrivateUsers = mkForce false;
ProtectHostname = mkForce false;
ProtectClock = mkForce false;
ProtectKernelTunables = mkForce false;
ProtectKernelModules = mkForce false;
ProtectKernelLogs = mkForce false;
RestrictAddressFamilies = mkForce [ ];
LockPersonality = mkForce false;
MemoryDenyWriteExecute = mkForce false;
RestrictRealtime = mkForce false;
RestrictSUIDSGID = mkForce false;
SystemCallArchitectures = mkForce "";
SystemCallFilter = mkForce [ ];
};
eilean.dns.enable = true;
eilean.services.dns.zones.${config.networking.domain}.records = [{
name = "git";
type = "CNAME";
value = cfg.domainName;
}];
# proxy port 22 on ethernet interface to internal gitea ssh server
# openssh server remains accessible on port 22 via vpn(s)
# allow forwarding
boot.kernel.sysctl = {
"net.ipv4.ip_forward" = 1;
"net.ipv6.conf.all.forwarding" = 1;
};
networking.firewall = {
allowedTCPPorts = [ 22 cfg.gitea.sshPort ];
extraCommands = ''
# proxy all traffic on public interface to the gitea SSH server
iptables -A PREROUTING -t nat -i ${config.eilean.publicInterface} -p tcp --dport 22 -j REDIRECT --to-port ${
builtins.toString cfg.gitea.sshPort
}
ip6tables -A PREROUTING -t nat -i ${config.eilean.publicInterface} -p tcp --dport 22 -j REDIRECT --to-port ${
builtins.toString cfg.gitea.sshPort
}
# proxy locally originating outgoing packets
iptables -A OUTPUT -d ${config.eilean.serverIpv4} -t nat -p tcp --dport 22 -j REDIRECT --to-port ${
builtins.toString cfg.gitea.sshPort
}
ip6tables -A OUTPUT -d ${config.eilean.serverIpv6} -t nat -p tcp --dport 22 -j REDIRECT --to-port ${
builtins.toString cfg.gitea.sshPort
}
'';
};
services.gitea.settings.server = {
START_SSH_SERVER = true;
SSH_LISTEN_PORT = cfg.gitea.sshPort;
};
};
}