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 = [
137 config = (import (pkgs.path + "/nixos/lib/eval-config.nix") {
138 inherit pkgs; modules = [ qemuConfig ];
139 system = "x86_64-linux";
142 import (pkgs.path + "/nixos/lib/make-disk-image.nix") {
143 inherit pkgs lib config;
145 format = "qcow2-compressed";
148 source = pkgs.writeText "gitconfig" ''
153 target = "/home/build/.gitconfig";
162 #dispatch.enable = true;
168 #pages.enable = true;
169 #paste.enable = true;
171 #lists.enable = true;
173 postgresql.enable = true;
174 postfix.enable = true;
179 environment = "production";
180 global-domain = domain;
181 origin = "http://${domain}";
182 owner-email = "julm+srht@sourcephile.fr";
183 owner-name = "Sourcephile";
184 site-blurb = "software forge";
185 site-info = "http://${domain}";
186 site-name = "Sourcephile";
187 # nix shell nixpkgs#sourcehut.coresrht -c srht-keygen network
188 network-key = gnupg.secrets."sourcehut/network-key".path;
189 # nix shell nixpkgs#sourcehut.coresrht -c srht-keygen service
190 service-key = gnupg.secrets."sourcehut/service-key".path;
193 s3-upstream = "localhost";
194 s3-access-key = "12345";
195 s3-secret-key = pkgs.writeText "s3-secret-key" "12345678";
197 # nix shell nixpkgs#sourcehut.metasrht -c metasrht-manageuser -t admin -e mymail@gmail.com misuzu
199 origin = "http://builds.${domain}";
200 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
201 oauth-client-id = "299db9f9c2013170";
205 origin = "http://dispatch.${domain}";
206 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
207 oauth-client-id = "299db9f9c2013170";
210 origin = "http://pages.${domain}";
211 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
212 oauth-client-id = "299db9f9c2013170";
213 s3-bucket = "pagesbuck";
216 origin = "http://paste.${domain}";
217 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
218 oauth-client-id = "299db9f9c2013170";
221 origin = "http://man.${domain}";
222 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
223 oauth-client-id = "299db9f9c2013170";
226 origin = "http://meta.${domain}";
227 api-origin = "http://localhost:5099";
229 "meta.sr.ht::settings" = {
230 onboarding-redirect = "http://meta.${domain}";
233 "meta.sr.ht::api" = {
234 # This is a temporary workaround
236 internal-ipnet = [ "127.0.0.0/8" "::1/128" "192.168.0.0/16" "10.0.0.0/8" ];
239 origin = "http://todo.${domain}";
240 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
241 oauth-client-id = "299db9f9c2013170";
244 origin = "http://git.${domain}";
245 outgoing-domain = "http://git.${domain}";
246 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
247 oauth-client-id = "299db9f9c2013170";
248 #repos = "/var/lib/git";
251 origin = "http://hub.${domain}";
252 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
253 oauth-client-id = "299db9f9c2013170";
256 origin = "http://lists.${domain}";
257 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
258 oauth-client-id = "299db9f9c2013170";
260 "lists.sr.ht::worker" = {
261 #sock = "/var/lib/postfix/queue/private/srht-lmtp";
263 # nix shell nixpkgs#sourcehut.coresrht -c srht-keygen webhook
264 #webhooks.private-key= "U7yd/8mGs/v0O3kId4jpeSghUCa9tqP1fYQwSV8UOqo=";
265 webhooks.private-key = gnupg.secrets."sourcehut/webhook-key".path;
267 smtp-host = "localhost";
270 smtp-password = null;
271 smtp-from = "sourcehut@sourcephile.fr";
272 error-to = "julm+sourcehut+error@sourcephile.fr";
273 error-from = "sourcehut+error@sourcephile.fr";
280 services.nginx.virtualHosts = {
281 "builds.${domain}".forceSSL = lib.mkForce false;
282 "dispatch.${domain}".forceSSL = lib.mkForce false;
283 "git.${domain}".forceSSL = lib.mkForce false;
284 "hub.${domain}".forceSSL = lib.mkForce false;
285 "lists.${domain}".forceSSL = lib.mkForce false;
286 "logs.${domain}".forceSSL = lib.mkForce false;
287 "man.${domain}".forceSSL = lib.mkForce false;
288 "paste.${domain}".forceSSL = lib.mkForce false;
289 "pages.${domain}".forceSSL = lib.mkForce false;
290 "todo.${domain}".forceSSL = lib.mkForce false;
292 forceSSL = lib.mkForce false;
295 access_log /var/log/nginx/${domain}/meta/access.log json;
296 error_log /var/log/nginx/${domain}/meta/error.log warn;
300 "${domain}".forceSSL = lib.mkForce false;
302 systemd.services.postgresql = {
304 connection_limit=64 \
306 lc_collate=fr_FR.UTF-8 \
307 lc_type=fr_FR.UTF-8 \
308 owner="${sourcehut.git.postgresql.database}" \
309 pg_createdb "${sourcehut.git.postgresql.database}" >/dev/null </dev/null
311 pg_adduser "${sourcehut.git.postgresql.database}" "${sourcehut.git.postgresql.database}" >/dev/null
312 postStart = lib.mkAfter ''
313 $PSQL -d "${sourcehut.builds.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
314 GRANT USAGE,CREATE ON schema public TO "${sourcehut.builds.user}";
316 $PSQL -d "${sourcehut.dispatch.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
317 GRANT USAGE,CREATE ON schema public TO "${sourcehut.dispatch.user}";
319 $PSQL -d "${sourcehut.git.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
320 GRANT USAGE,CREATE ON schema public TO "${sourcehut.git.user}";
322 $PSQL -d "${sourcehut.hub.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
323 GRANT USAGE,CREATE ON schema public TO "${sourcehut.hub.user}";
325 $PSQL -d "${sourcehut.man.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
326 GRANT USAGE,CREATE ON schema public TO "${sourcehut.man.user}";
328 $PSQL -d "${sourcehut.meta.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
329 GRANT USAGE,CREATE ON schema public TO "${sourcehut.meta.user}";
330 GRANT USAGE,CREATE ON schema public TO "${users.sshsrht.name}";
332 $PSQL -d "${sourcehut.pages.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
333 GRANT USAGE,CREATE ON schema public TO "${sourcehut.pages.user}";
335 $PSQL -d "${sourcehut.paste.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
336 GRANT USAGE,CREATE ON schema public TO "${sourcehut.paste.user}";
338 $PSQL -d "${sourcehut.todo.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
339 GRANT USAGE,CREATE ON schema public TO "${sourcehut.todo.user}";
341 $PSQL -d "${sourcehut.lists.postgresql.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
342 GRANT USAGE,CREATE ON schema public TO "${sourcehut.lists.user}";