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 = ''
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"
42 systemdConfig.before = [ "metasrht.service" "gitsrht.service" ];
43 systemdConfig.wantedBy = [ "metasrht.service" "gitsrht.service" ];
48 secretKey = "12345678";
52 environment.systemPackages = [ pkgs.minio-client ];
53 services.sourcehut = {
55 listenAddress = "localhost";
59 images.nixos.unstable.x86_64 = let
60 systemConfig = { pkgs, ... }: {
61 # passwordless ssh server
64 permitRootLogin = "yes";
65 extraConfig = "PermitEmptyPasswords yes";
71 extraUsers."build" = {
74 extraGroups = [ "wheel" ];
77 users.root.password = "";
80 security.sudo.wheelNeedsPassword = false;
81 nix.settings.trusted-users = [ "root" "build" ];
82 documentation.nixos.enable = false;
84 # builds.sr.ht-image-specific network settings
87 dhcpcd.enable = false;
88 defaultGateway.address = "10.0.2.2";
89 usePredictableInterfaceNames = false; # so that we just get eth0 and not some weird id
90 interfaces."eth0".ipv4.addresses = [{
91 address = "10.0.2.15";
99 # Google as a fallback :(
102 firewall.allowedTCPPorts = [ 22 ]; # allow ssh
105 environment.systemPackages = [
112 qemuConfig = { pkgs, ... }: {
113 imports = [ systemConfig ];
114 fileSystems."/".device = "/dev/disk/by-label/nixos";
115 boot.initrd.availableKernelModules = [
135 config = (import (pkgs.path + "/nixos/lib/eval-config.nix") {
136 inherit pkgs; modules = [ qemuConfig ];
137 system = "x86_64-linux";
140 import (pkgs.path + "/nixos/lib/make-disk-image.nix") {
141 inherit pkgs lib config;
143 format = "qcow2-compressed";
145 { source = pkgs.writeText "gitconfig" ''
150 target = "/home/build/.gitconfig";
159 #dispatch.enable = true;
165 #pages.enable = true;
166 #paste.enable = true;
168 #lists.enable = true;
170 postgresql.enable = true;
171 postfix.enable = true;
176 environment = "production";
177 global-domain = domain;
178 origin = "http://${domain}";
179 owner-email = "julm+srht@sourcephile.fr";
180 owner-name = "Sourcephile";
181 site-blurb = "software forge";
182 site-info = "http://${domain}";
183 site-name = "Sourcephile";
184 # nix shell nixpkgs#sourcehut.coresrht -c srht-keygen network
185 network-key = gnupg.secrets."sourcehut/network-key".path;
186 # nix shell nixpkgs#sourcehut.coresrht -c srht-keygen service
187 service-key = gnupg.secrets."sourcehut/service-key".path;
190 s3-upstream = "localhost";
191 s3-access-key = "12345";
192 s3-secret-key = pkgs.writeText "s3-secret-key" "12345678";
194 # nix shell nixpkgs#sourcehut.metasrht -c metasrht-manageuser -t admin -e mymail@gmail.com misuzu
196 origin = "http://builds.${domain}";
197 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
198 oauth-client-id = "299db9f9c2013170";
202 origin = "http://dispatch.${domain}";
203 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
204 oauth-client-id = "299db9f9c2013170";
207 origin = "http://pages.${domain}";
208 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
209 oauth-client-id = "299db9f9c2013170";
210 s3-bucket = "pagesbuck";
213 origin = "http://paste.${domain}";
214 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
215 oauth-client-id = "299db9f9c2013170";
218 origin = "http://man.${domain}";
219 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
220 oauth-client-id = "299db9f9c2013170";
223 origin = "http://meta.${domain}";
224 api-origin = "http://localhost:5099";
226 "meta.sr.ht::settings" = {
227 onboarding-redirect = "http://meta.${domain}";
230 "meta.sr.ht::api" = {
231 # This is a temporary workaround
233 internal-ipnet= [ "127.0.0.0/8" "::1/128" "192.168.0.0/16" "10.0.0.0/8"];
236 origin = "http://todo.${domain}";
237 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
238 oauth-client-id = "299db9f9c2013170";
241 origin = "http://git.${domain}";
242 outgoing-domain = "http://git.${domain}";
243 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
244 oauth-client-id = "299db9f9c2013170";
245 #repos = "/var/lib/git";
248 origin = "http://hub.${domain}";
249 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
250 oauth-client-id = "299db9f9c2013170";
253 origin = "http://lists.${domain}";
254 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
255 oauth-client-id = "299db9f9c2013170";
257 "lists.sr.ht::worker" = {
258 #sock = "/var/lib/postfix/queue/private/srht-lmtp";
260 # nix shell nixpkgs#sourcehut.coresrht -c srht-keygen webhook
261 #webhooks.private-key= "U7yd/8mGs/v0O3kId4jpeSghUCa9tqP1fYQwSV8UOqo=";
262 webhooks.private-key = gnupg.secrets."sourcehut/webhook-key".path;
264 smtp-host = "localhost";
267 smtp-password = null;
268 smtp-from = "sourcehut@sourcephile.fr";
269 error-to = "julm+sourcehut+error@sourcephile.fr";
270 error-from = "sourcehut+error@sourcephile.fr";
277 services.nginx.virtualHosts = {
278 "builds.${domain}".forceSSL = lib.mkForce false;
279 "dispatch.${domain}".forceSSL = lib.mkForce false;
280 "git.${domain}".forceSSL = lib.mkForce false;
281 "hub.${domain}".forceSSL = lib.mkForce false;
282 "lists.${domain}".forceSSL = lib.mkForce false;
283 "logs.${domain}".forceSSL = lib.mkForce false;
284 "man.${domain}".forceSSL = lib.mkForce false;
285 "paste.${domain}".forceSSL = lib.mkForce false;
286 "pages.${domain}".forceSSL = lib.mkForce false;
287 "todo.${domain}".forceSSL = lib.mkForce false;
289 forceSSL = lib.mkForce false;
292 access_log /var/log/nginx/${domain}/meta/access.log json;
293 error_log /var/log/nginx/${domain}/meta/error.log warn;
297 "${domain}".forceSSL = lib.mkForce false;
299 systemd.services.postgresql = {
301 connection_limit=64 \
303 lc_collate=fr_FR.UTF-8 \
304 lc_type=fr_FR.UTF-8 \
305 owner="${sourcehut.git.postgresql.database}" \
306 pg_createdb "${sourcehut.git.postgresql.database}" >/dev/null </dev/null
308 pg_adduser "${sourcehut.git.postgresql.database}" "${sourcehut.git.postgresql.database}" >/dev/null
309 postStart = lib.mkAfter ''
310 $PSQL -d "${sourcehut.builds.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
311 GRANT USAGE,CREATE ON schema public TO "${sourcehut.builds.user}";
313 $PSQL -d "${sourcehut.dispatch.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
314 GRANT USAGE,CREATE ON schema public TO "${sourcehut.dispatch.user}";
316 $PSQL -d "${sourcehut.git.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
317 GRANT USAGE,CREATE ON schema public TO "${sourcehut.git.user}";
319 $PSQL -d "${sourcehut.hub.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
320 GRANT USAGE,CREATE ON schema public TO "${sourcehut.hub.user}";
322 $PSQL -d "${sourcehut.man.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
323 GRANT USAGE,CREATE ON schema public TO "${sourcehut.man.user}";
325 $PSQL -d "${sourcehut.meta.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
326 GRANT USAGE,CREATE ON schema public TO "${sourcehut.meta.user}";
327 GRANT USAGE,CREATE ON schema public TO "${users.sshsrht.name}";
329 $PSQL -d "${sourcehut.pages.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
330 GRANT USAGE,CREATE ON schema public TO "${sourcehut.pages.user}";
332 $PSQL -d "${sourcehut.paste.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
333 GRANT USAGE,CREATE ON schema public TO "${sourcehut.paste.user}";
335 $PSQL -d "${sourcehut.todo.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
336 GRANT USAGE,CREATE ON schema public TO "${sourcehut.todo.user}";
338 $PSQL -d "${sourcehut.lists.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
339 GRANT USAGE,CREATE ON schema public TO "${sourcehut.lists.user}";