1 { pkgs, lib, config, ... }:
3 inherit (config.services) sourcehut;
4 inherit (config.users) users;
5 inherit (config.security) gnupg;
6 domain = "sourcephile.wg";
22 #boot.isContainer = true;
23 #networking.firewall.allowedTCPPorts = [ 80 ];
25 "192.168.42.2" = [ domain ] ++ map (d: "${d}.${domain}") sourcehut-services;
27 networking.nftables.ruleset = ''
30 skuid ${sourcehut.meta.user} \
31 tcp dport smtp counter \
32 accept comment "sourcehut: SMTP"
36 security.gnupg.secrets = lib.genAttrs [
37 "sourcehut/network-key"
38 "sourcehut/service-key"
39 "sourcehut/webhook-key"
40 "sourcehut/oauth-client-secret"
43 systemdConfig.before = [ "metasrht.service" "gitsrht.service" ];
44 systemdConfig.wantedBy = [ "metasrht.service" "gitsrht.service" ];
49 secretKey = "12345678";
53 environment.systemPackages = [ pkgs.minio-client ];
54 services.sourcehut = {
56 listenAddress = "localhost";
60 images.nixos.unstable.x86_64 =
62 systemConfig = { pkgs, ... }: {
63 # passwordless ssh server
66 permitRootLogin = "yes";
67 extraConfig = "PermitEmptyPasswords yes";
73 extraUsers."build" = {
76 extraGroups = [ "wheel" ];
79 users.root.password = "";
82 security.sudo.wheelNeedsPassword = false;
83 nix.settings.trusted-users = [ "root" "build" ];
84 documentation.nixos.enable = false;
86 # builds.sr.ht-image-specific network settings
89 dhcpcd.enable = false;
90 defaultGateway.address = "10.0.2.2";
91 usePredictableInterfaceNames = false; # so that we just get eth0 and not some weird id
92 interfaces."eth0".ipv4.addresses = [{
93 address = "10.0.2.15";
101 # Google as a fallback :(
104 firewall.allowedTCPPorts = [ 22 ]; # allow ssh
107 environment.systemPackages = [
114 qemuConfig = { ... }: {
115 imports = [ systemConfig ];
116 fileSystems."/".device = "/dev/disk/by-label/nixos";
117 boot.initrd.availableKernelModules = [
136 config = (import (pkgs.path + "/nixos/lib/eval-config.nix") {
137 inherit pkgs; modules = [ qemuConfig ];
138 system = "x86_64-linux";
141 import (pkgs.path + "/nixos/lib/make-disk-image.nix") {
142 inherit pkgs lib config;
144 format = "qcow2-compressed";
147 source = pkgs.writeText "gitconfig" ''
152 target = "/home/build/.gitconfig";
161 #dispatch.enable = true;
167 #pages.enable = true;
168 #paste.enable = true;
170 #lists.enable = true;
172 postgresql.enable = true;
173 postfix.enable = true;
178 environment = "production";
179 global-domain = domain;
180 origin = "http://${domain}";
181 owner-email = "julm+srht@sourcephile.fr";
182 owner-name = "Sourcephile";
183 site-blurb = "software forge";
184 site-info = "http://${domain}";
185 site-name = "Sourcephile";
186 # nix shell nixpkgs#sourcehut.coresrht -c srht-keygen network
187 network-key = gnupg.secrets."sourcehut/network-key".path;
188 # nix shell nixpkgs#sourcehut.coresrht -c srht-keygen service
189 service-key = gnupg.secrets."sourcehut/service-key".path;
192 s3-upstream = "localhost";
193 s3-access-key = "12345";
194 s3-secret-key = pkgs.writeText "s3-secret-key" "12345678";
196 # nix shell nixpkgs#sourcehut.metasrht -c metasrht-manageuser -t admin -e mymail@gmail.com misuzu
198 origin = "http://builds.${domain}";
199 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
200 oauth-client-id = "299db9f9c2013170";
204 origin = "http://dispatch.${domain}";
205 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
206 oauth-client-id = "299db9f9c2013170";
209 origin = "http://pages.${domain}";
210 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
211 oauth-client-id = "299db9f9c2013170";
212 s3-bucket = "pagesbuck";
215 origin = "http://paste.${domain}";
216 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
217 oauth-client-id = "299db9f9c2013170";
220 origin = "http://man.${domain}";
221 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
222 oauth-client-id = "299db9f9c2013170";
225 origin = "http://meta.${domain}";
226 api-origin = "http://localhost:5099";
228 "meta.sr.ht::settings" = {
229 onboarding-redirect = "http://meta.${domain}";
232 "meta.sr.ht::api" = {
233 # This is a temporary workaround
235 internal-ipnet = [ "127.0.0.0/8" "::1/128" "192.168.0.0/16" "10.0.0.0/8" ];
238 origin = "http://todo.${domain}";
239 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
240 oauth-client-id = "299db9f9c2013170";
243 origin = "http://git.${domain}";
244 outgoing-domain = "http://git.${domain}";
245 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
246 oauth-client-id = "299db9f9c2013170";
247 #repos = "/var/lib/git";
250 origin = "http://hub.${domain}";
251 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
252 oauth-client-id = "299db9f9c2013170";
255 origin = "http://lists.${domain}";
256 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
257 oauth-client-id = "299db9f9c2013170";
259 "lists.sr.ht::worker" = {
260 #sock = "/var/lib/postfix/queue/private/srht-lmtp";
262 # nix shell nixpkgs#sourcehut.coresrht -c srht-keygen webhook
263 #webhooks.private-key= "U7yd/8mGs/v0O3kId4jpeSghUCa9tqP1fYQwSV8UOqo=";
264 webhooks.private-key = gnupg.secrets."sourcehut/webhook-key".path;
266 smtp-host = "localhost";
269 smtp-password = null;
270 smtp-from = "sourcehut@sourcephile.fr";
271 error-to = "julm+sourcehut+error@sourcephile.fr";
272 error-from = "sourcehut+error@sourcephile.fr";
279 services.nginx.virtualHosts = {
280 "builds.${domain}".forceSSL = lib.mkForce false;
281 "dispatch.${domain}".forceSSL = lib.mkForce false;
282 "git.${domain}".forceSSL = lib.mkForce false;
283 "hub.${domain}".forceSSL = lib.mkForce false;
284 "lists.${domain}".forceSSL = lib.mkForce false;
285 "logs.${domain}".forceSSL = lib.mkForce false;
286 "man.${domain}".forceSSL = lib.mkForce false;
287 "paste.${domain}".forceSSL = lib.mkForce false;
288 "pages.${domain}".forceSSL = lib.mkForce false;
289 "todo.${domain}".forceSSL = lib.mkForce false;
291 forceSSL = lib.mkForce false;
294 access_log /var/log/nginx/${domain}/meta/access.log json;
295 error_log /var/log/nginx/${domain}/meta/error.log warn;
299 "${domain}".forceSSL = lib.mkForce false;
301 systemd.services.postgresql = {
303 connection_limit=64 \
305 lc_collate=fr_FR.UTF-8 \
306 lc_type=fr_FR.UTF-8 \
307 owner="${sourcehut.git.postgresql.database}" \
308 pg_createdb "${sourcehut.git.postgresql.database}" >/dev/null </dev/null
310 pg_adduser "${sourcehut.git.postgresql.database}" "${sourcehut.git.postgresql.database}" >/dev/null
311 postStart = lib.mkAfter ''
312 $PSQL -d "${sourcehut.builds.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
313 GRANT USAGE,CREATE ON schema public TO "${sourcehut.builds.user}";
315 $PSQL -d "${sourcehut.dispatch.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
316 GRANT USAGE,CREATE ON schema public TO "${sourcehut.dispatch.user}";
318 $PSQL -d "${sourcehut.git.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
319 GRANT USAGE,CREATE ON schema public TO "${sourcehut.git.user}";
321 $PSQL -d "${sourcehut.hub.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
322 GRANT USAGE,CREATE ON schema public TO "${sourcehut.hub.user}";
324 $PSQL -d "${sourcehut.man.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
325 GRANT USAGE,CREATE ON schema public TO "${sourcehut.man.user}";
327 $PSQL -d "${sourcehut.meta.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
328 GRANT USAGE,CREATE ON schema public TO "${sourcehut.meta.user}";
329 GRANT USAGE,CREATE ON schema public TO "${users.sshsrht.name}";
331 $PSQL -d "${sourcehut.pages.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
332 GRANT USAGE,CREATE ON schema public TO "${sourcehut.pages.user}";
334 $PSQL -d "${sourcehut.paste.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
335 GRANT USAGE,CREATE ON schema public TO "${sourcehut.paste.user}";
337 $PSQL -d "${sourcehut.todo.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
338 GRANT USAGE,CREATE ON schema public TO "${sourcehut.todo.user}";
340 $PSQL -d "${sourcehut.lists.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
341 GRANT USAGE,CREATE ON schema public TO "${sourcehut.lists.user}";