1 { pkgs, lib, config, inputs, ... }:
3 inherit (config.services) sourcehut;
4 inherit (config.users) users groups;
5 inherit (config.security) gnupg;
6 domain = "sourcephile.wg";
21 #boot.isContainer = true;
22 #networking.firewall.allowedTCPPorts = [ 80 ];
24 "192.168.42.2" = [domain] ++ map (d: "${d}.${domain}") sourcehut-services;
26 networking.nftables.ruleset = ''
27 add rule inet filter fw2net meta skuid ${sourcehut.meta.user} tcp dport 25 counter accept comment "SMTP"
29 security.gnupg.secrets = lib.genAttrs [
30 "sourcehut/network-key"
31 "sourcehut/service-key"
32 "sourcehut/webhook-key"
33 "sourcehut/oauth-client-secret"
35 systemdConfig.before = [ "metasrht.service" ];
36 systemdConfig.wantedBy = [ "metasrht.service" ];
41 secretKey = "12345678";
45 environment.systemPackages = [ pkgs.minio-client ];
46 services.sourcehut = {
48 listenAddress = domain;
52 images.nixos.unstable.x86_64 =
54 makeDiskImage = import (inputs.nixpkgs + "/nixos/lib/make-disk-image.nix");
55 evalConfig = import (inputs.nixpkgs + "/nixos/lib/eval-config.nix");
56 systemConfig = { pkgs, ... }: {
57 # passwordless ssh server
60 permitRootLogin = "yes";
61 extraConfig = "PermitEmptyPasswords yes";
67 extraUsers."build" = {
70 extraGroups = [ "wheel" ];
73 users.root.password = "";
76 security.sudo.wheelNeedsPassword = false;
77 nix.trustedUsers = [ "root" "build" ];
78 documentation.nixos.enable = false;
80 # builds.sr.ht-image-specific network settings
83 dhcpcd.enable = false;
84 defaultGateway.address = "10.0.2.2";
85 usePredictableInterfaceNames = false; # so that we just get eth0 and not some weird id
86 interfaces."eth0".ipv4.addresses = [{
87 address = "10.0.2.15";
95 # Google as a fallback :(
98 firewall.allowedTCPPorts = [ 22 ]; # allow ssh
101 environment.systemPackages = [
108 qemuConfig = { pkgs, ... }: {
109 imports = [ systemConfig ];
110 fileSystems."/".device = "/dev/disk/by-label/nixos";
111 boot.initrd.availableKernelModules = [
131 config = (evalConfig {
132 inherit pkgs; modules = [ qemuConfig ];
133 system = "x86_64-linux";
137 inherit pkgs lib config;
139 format = "qcow2-compressed";
141 { source = pkgs.writeText "gitconfig" ''
146 target = "/home/build/.gitconfig";
155 #dispatch.enable = true;
160 #pages.enable = true;
161 #paste.enable = true;
163 #lists.enable = true;
165 postgresql.enable = true;
166 postfix.enable = true;
168 #redis.firstDatabase = 0;
172 environment = "production";
173 global-domain = domain;
174 origin = "http://${domain}";
175 owner-email = "julm+srht@sourcephile.fr";
176 owner-name = "Sourcephile";
177 site-blurb = "software forge";
178 site-info = "http://${domain}";
179 site-name = "Sourcephile";
180 # nix shell nixpkgs#sourcehut.coresrht -c srht-keygen network
181 network-key = gnupg.secrets."sourcehut/network-key".path;
182 # nix shell nixpkgs#sourcehut.coresrht -c srht-keygen service
183 service-key = gnupg.secrets."sourcehut/service-key".path;
186 s3-upstream = "localhost";
187 s3-access-key = "12345";
188 s3-secret-key = pkgs.writeText "s3-secret-key" "12345678";
190 # nix shell nixpkgs#sourcehut.metasrht -c metasrht-manageuser -t admin -e mymail@gmail.com misuzu
192 origin = "http://builds.${domain}";
193 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
194 oauth-client-id = "299db9f9c2013170";
198 origin = "http://dispatch.${domain}";
199 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
200 oauth-client-id = "299db9f9c2013170";
203 origin = "http://pages.${domain}";
204 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
205 oauth-client-id = "299db9f9c2013170";
206 s3-bucket = "pagesbuck";
209 origin = "http://paste.${domain}";
210 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
211 oauth-client-id = "299db9f9c2013170";
214 origin = "http://man.${domain}";
215 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
216 oauth-client-id = "299db9f9c2013170";
219 origin = "http://meta.${domain}";
220 api-origin = "http://meta.${domain}:5100";
222 "meta.sr.ht::settings" = {
223 onboarding-redirect = "http://meta.${domain}";
225 internal-ipnet = "127.0.0.0/8,192.168.42.0/24";
227 "meta.sr.ht::api" = {
228 internal-ipnet= [ "127.0.0.0/8" "::1/128" "192.168.0.0/16" "10.0.0.0/8"];
231 origin = "http://todo.${domain}";
232 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
233 oauth-client-id = "299db9f9c2013170";
236 origin = "http://git.${domain}";
237 outgoing-domain = "http://git.${domain}";
238 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
239 oauth-client-id = "299db9f9c2013170";
240 repos = "/var/lib/git";
243 origin = "http://hub.${domain}";
244 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
245 oauth-client-id = "299db9f9c2013170";
248 origin = "http://lists.${domain}";
249 oauth-client-secret = gnupg.secrets."sourcehut/oauth-client-secret".path;
250 oauth-client-id = "299db9f9c2013170";
252 "lists.sr.ht::worker" = {
253 #sock = "/var/lib/postfix/queue/private/srht-lmtp";
255 # nix shell nixpkgs#sourcehut.coresrht -c srht-keygen webhook
256 #webhooks.private-key= "U7yd/8mGs/v0O3kId4jpeSghUCa9tqP1fYQwSV8UOqo=";
257 webhooks.private-key = gnupg.secrets."sourcehut/webhook-key".path;
259 smtp-host = "localhost";
262 smtp-password = null;
263 smtp-from = "sourcehut@sourcephile.fr";
264 error-to = "julm+sourcehut+error@sourcephile.fr";
265 error-from = "sourcehut+error@sourcephile.fr";
272 services.nginx.virtualHosts = {
273 "builds.${domain}".forceSSL = lib.mkForce false;
274 "dispatch.${domain}".forceSSL = lib.mkForce false;
275 "git.${domain}".forceSSL = lib.mkForce false;
276 "hub.${domain}".forceSSL = lib.mkForce false;
277 "lists.${domain}".forceSSL = lib.mkForce false;
278 "logs.${domain}".forceSSL = lib.mkForce false;
279 "man.${domain}".forceSSL = lib.mkForce false;
280 "paste.${domain}".forceSSL = lib.mkForce false;
281 "pages.${domain}".forceSSL = lib.mkForce false;
282 "todo.${domain}".forceSSL = lib.mkForce false;
284 forceSSL = lib.mkForce false;
287 access_log /var/log/nginx/${domain}/meta/access.log json;
288 error_log /var/log/nginx/${domain}/meta/error.log warn;
292 "${domain}".forceSSL = lib.mkForce false;
294 systemd.services.postgresql = {
296 connection_limit=64 \
298 lc_collate=fr_FR.UTF-8 \
299 lc_type=fr_FR.UTF-8 \
300 owner="${sourcehut.git.database}" \
301 pg_createdb "${sourcehut.git.database}" >/dev/null </dev/null
303 pg_adduser "${sourcehut.git.database}" "${sourcehut.git.database}" >/dev/null
305 postStart = lib.mkAfter ''
306 $PSQL -d "${sourcehut.builds.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
307 GRANT USAGE,CREATE ON schema public TO "${sourcehut.builds.user}";
309 $PSQL -d "${sourcehut.dispatch.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
310 GRANT USAGE,CREATE ON schema public TO "${sourcehut.dispatch.user}";
312 $PSQL -d "${sourcehut.git.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
313 GRANT USAGE,CREATE ON schema public TO "${sourcehut.git.user}";
315 $PSQL -d "${sourcehut.hub.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
316 GRANT USAGE,CREATE ON schema public TO "${sourcehut.hub.user}";
318 $PSQL -d "${sourcehut.man.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
319 GRANT USAGE,CREATE ON schema public TO "${sourcehut.man.user}";
321 $PSQL -d "${sourcehut.meta.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
322 GRANT USAGE,CREATE ON schema public TO "${sourcehut.meta.user}";
323 GRANT USAGE,CREATE ON schema public TO "${users.sshsrht.name}";
325 $PSQL -d "${sourcehut.pages.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
326 GRANT USAGE,CREATE ON schema public TO "${sourcehut.pages.user}";
328 $PSQL -d "${sourcehut.paste.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
329 GRANT USAGE,CREATE ON schema public TO "${sourcehut.paste.user}";
331 $PSQL -d "${sourcehut.todo.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
332 GRANT USAGE,CREATE ON schema public TO "${sourcehut.todo.user}";
334 $PSQL -d "${sourcehut.lists.database}" -AqtX --set ON_ERROR_STOP=1 -f - <<EOF
335 GRANT USAGE,CREATE ON schema public TO "${sourcehut.lists.user}";