1 { pkgs, lib, config, ... }:
3 inherit (config.services) sourcehut;
4 inherit (config.users) users groups;
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 = ''
28 add rule inet filter fw2net meta skuid ${sourcehut.meta.user} tcp dport 25 counter accept comment "SMTP"
30 security.gnupg.secrets = lib.genAttrs [
31 "sourcehut/network-key"
32 "sourcehut/service-key"
33 "sourcehut/webhook-key"
34 "sourcehut/oauth-client-secret"
36 systemdConfig.before = [ "metasrht.service" "gitsrht.service" ];
37 systemdConfig.wantedBy = [ "metasrht.service" "gitsrht.service" ];
42 secretKey = "12345678";
46 environment.systemPackages = [ pkgs.minio-client ];
47 services.sourcehut = {
49 listenAddress = "localhost";
53 images.nixos.unstable.x86_64 = let
54 systemConfig = { pkgs, ... }: {
55 # passwordless ssh server
58 permitRootLogin = "yes";
59 extraConfig = "PermitEmptyPasswords yes";
65 extraUsers."build" = {
68 extraGroups = [ "wheel" ];
71 users.root.password = "";
74 security.sudo.wheelNeedsPassword = false;
75 nix.trustedUsers = [ "root" "build" ];
76 documentation.nixos.enable = false;
78 # builds.sr.ht-image-specific network settings
81 dhcpcd.enable = false;
82 defaultGateway.address = "10.0.2.2";
83 usePredictableInterfaceNames = false; # so that we just get eth0 and not some weird id
84 interfaces."eth0".ipv4.addresses = [{
85 address = "10.0.2.15";
93 # Google as a fallback :(
96 firewall.allowedTCPPorts = [ 22 ]; # allow ssh
99 environment.systemPackages = [
106 qemuConfig = { pkgs, ... }: {
107 imports = [ systemConfig ];
108 fileSystems."/".device = "/dev/disk/by-label/nixos";
109 boot.initrd.availableKernelModules = [
129 config = (import (pkgs.path + "/nixos/lib/eval-config.nix") {
130 inherit pkgs; modules = [ qemuConfig ];
131 system = "x86_64-linux";
134 import (pkgs.path + "/nixos/lib/make-disk-image.nix") {
135 inherit pkgs lib config;
137 format = "qcow2-compressed";
139 { source = pkgs.writeText "gitconfig" ''
144 target = "/home/build/.gitconfig";
153 #dispatch.enable = true;
159 #pages.enable = true;
160 #paste.enable = true;
162 #lists.enable = true;
164 postgresql.enable = true;
165 postfix.enable = true;
170 environment = "production";
171 global-domain = domain;
172 origin = "http://${domain}";
173 owner-email = "julm+srht@sourcephile.fr";
174 owner-name = "Sourcephile";
175 site-blurb = "software forge";
176 site-info = "http://${domain}";
177 site-name = "Sourcephile";
178 # nix shell nixpkgs#sourcehut.coresrht -c srht-keygen network
179 network-key = gnupg.secrets."sourcehut/network-key".path;
180 # nix shell nixpkgs#sourcehut.coresrht -c srht-keygen service
181 service-key = gnupg.secrets."sourcehut/service-key".path;
184 s3-upstream = "localhost";
185 s3-access-key = "12345";
186 s3-secret-key = pkgs.writeText "s3-secret-key" "12345678";
188 # nix shell nixpkgs#sourcehut.metasrht -c metasrht-manageuser -t admin -e mymail@gmail.com misuzu
190 origin = "http://builds.${domain}";
191 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
192 oauth-client-id = "299db9f9c2013170";
196 origin = "http://dispatch.${domain}";
197 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
198 oauth-client-id = "299db9f9c2013170";
201 origin = "http://pages.${domain}";
202 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
203 oauth-client-id = "299db9f9c2013170";
204 s3-bucket = "pagesbuck";
207 origin = "http://paste.${domain}";
208 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
209 oauth-client-id = "299db9f9c2013170";
212 origin = "http://man.${domain}";
213 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
214 oauth-client-id = "299db9f9c2013170";
217 origin = "http://meta.${domain}";
218 api-origin = "http://localhost:5099";
220 "meta.sr.ht::settings" = {
221 onboarding-redirect = "http://meta.${domain}";
224 "meta.sr.ht::api" = {
225 # This is a temporary workaround
227 internal-ipnet= [ "127.0.0.0/8" "::1/128" "192.168.0.0/16" "10.0.0.0/8"];
230 origin = "http://todo.${domain}";
231 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
232 oauth-client-id = "299db9f9c2013170";
235 origin = "http://git.${domain}";
236 outgoing-domain = "http://git.${domain}";
237 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
238 oauth-client-id = "299db9f9c2013170";
239 #repos = "/var/lib/git";
242 origin = "http://hub.${domain}";
243 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
244 oauth-client-id = "299db9f9c2013170";
247 origin = "http://lists.${domain}";
248 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
249 oauth-client-id = "299db9f9c2013170";
251 "lists.sr.ht::worker" = {
252 #sock = "/var/lib/postfix/queue/private/srht-lmtp";
254 # nix shell nixpkgs#sourcehut.coresrht -c srht-keygen webhook
255 #webhooks.private-key= "U7yd/8mGs/v0O3kId4jpeSghUCa9tqP1fYQwSV8UOqo=";
256 webhooks.private-key = gnupg.secrets."sourcehut/webhook-key".path;
258 smtp-host = "localhost";
261 smtp-password = null;
262 smtp-from = "sourcehut@sourcephile.fr";
263 error-to = "julm+sourcehut+error@sourcephile.fr";
264 error-from = "sourcehut+error@sourcephile.fr";
271 services.nginx.virtualHosts = {
272 "builds.${domain}".forceSSL = lib.mkForce false;
273 "dispatch.${domain}".forceSSL = lib.mkForce false;
274 "git.${domain}".forceSSL = lib.mkForce false;
275 "hub.${domain}".forceSSL = lib.mkForce false;
276 "lists.${domain}".forceSSL = lib.mkForce false;
277 "logs.${domain}".forceSSL = lib.mkForce false;
278 "man.${domain}".forceSSL = lib.mkForce false;
279 "paste.${domain}".forceSSL = lib.mkForce false;
280 "pages.${domain}".forceSSL = lib.mkForce false;
281 "todo.${domain}".forceSSL = lib.mkForce false;
283 forceSSL = lib.mkForce false;
286 access_log /var/log/nginx/${domain}/meta/access.log json;
287 error_log /var/log/nginx/${domain}/meta/error.log warn;
291 "${domain}".forceSSL = lib.mkForce false;
293 systemd.services.postgresql = {
295 connection_limit=64 \
297 lc_collate=fr_FR.UTF-8 \
298 lc_type=fr_FR.UTF-8 \
299 owner="${sourcehut.git.postgresql.database}" \
300 pg_createdb "${sourcehut.git.postgresql.database}" >/dev/null </dev/null
302 pg_adduser "${sourcehut.git.postgresql.database}" "${sourcehut.git.postgresql.database}" >/dev/null
303 postStart = lib.mkAfter ''
304 $PSQL -d "${sourcehut.builds.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
305 GRANT USAGE,CREATE ON schema public TO "${sourcehut.builds.user}";
307 $PSQL -d "${sourcehut.dispatch.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
308 GRANT USAGE,CREATE ON schema public TO "${sourcehut.dispatch.user}";
310 $PSQL -d "${sourcehut.git.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
311 GRANT USAGE,CREATE ON schema public TO "${sourcehut.git.user}";
313 $PSQL -d "${sourcehut.hub.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
314 GRANT USAGE,CREATE ON schema public TO "${sourcehut.hub.user}";
316 $PSQL -d "${sourcehut.man.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
317 GRANT USAGE,CREATE ON schema public TO "${sourcehut.man.user}";
319 $PSQL -d "${sourcehut.meta.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
320 GRANT USAGE,CREATE ON schema public TO "${sourcehut.meta.user}";
321 GRANT USAGE,CREATE ON schema public TO "${users.sshsrht.name}";
323 $PSQL -d "${sourcehut.pages.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
324 GRANT USAGE,CREATE ON schema public TO "${sourcehut.pages.user}";
326 $PSQL -d "${sourcehut.paste.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
327 GRANT USAGE,CREATE ON schema public TO "${sourcehut.paste.user}";
329 $PSQL -d "${sourcehut.todo.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
330 GRANT USAGE,CREATE ON schema public TO "${sourcehut.todo.user}";
332 $PSQL -d "${sourcehut.lists.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
333 GRANT USAGE,CREATE ON schema public TO "${sourcehut.lists.user}";