1 import ./make-test-python.nix ({ pkgs, lib, ... }:
3 domain = "sourcehut.localdomain";
5 # Note that wildcard certificates just under the TLD (eg. *.com)
6 # would be rejected by clients like curl.
7 tls-cert = pkgs.runCommand "selfSignedCerts" { buildInputs = [ pkgs.openssl ]; } ''
8 openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -nodes -days 36500 \
9 -subj '/CN=${domain}' -extensions v3_req \
10 -addext 'subjectAltName = DNS:*.${domain}'
11 install -D -t $out key.pem cert.pem
15 nixos.unstable.x86_64 =
17 systemConfig = { pkgs, ... }: {
18 # passwordless ssh server
21 permitRootLogin = "yes";
22 extraConfig = "PermitEmptyPasswords yes";
28 extraUsers."build" = {
31 extraGroups = [ "wheel" ];
34 users.root.password = "";
37 security.sudo.wheelNeedsPassword = false;
38 nix.trustedUsers = [ "root" "build" ];
39 documentation.nixos.enable = false;
41 # builds.sr.ht-image-specific network settings
44 dhcpcd.enable = false;
45 defaultGateway.address = "10.0.2.2";
46 usePredictableInterfaceNames = false;
47 interfaces."eth0".ipv4.addresses = [{
48 address = "10.0.2.15";
59 firewall.allowedTCPPorts = [ 22 ];
62 environment.systemPackages = [
69 qemuConfig = { pkgs, ... }: {
70 imports = [ systemConfig ];
71 fileSystems."/".device = "/dev/disk/by-label/nixos";
72 boot.initrd.availableKernelModules = [
92 config = (import (pkgs.path + "/nixos/lib/eval-config.nix") {
93 inherit pkgs; modules = [ qemuConfig ];
94 system = "x86_64-linux";
97 import (pkgs.path + "/nixos/lib/make-disk-image.nix") {
98 inherit pkgs lib config;
100 format = "qcow2-compressed";
102 { source = pkgs.writeText "gitconfig" ''
107 target = "/home/build/.gitconfig";
120 meta.maintainers = [ pkgs.lib.maintainers.tomberek ];
122 nodes.machine = { config, pkgs, nodes, ... }: {
123 # buildsrht needs space
124 virtualisation.diskSize = 4 * 1024;
125 virtualisation.memorySize = 2 * 1024;
126 networking.domain = domain;
127 networking.extraHosts = ''
128 ${config.networking.primaryIPAddress} builds.${domain}
129 ${config.networking.primaryIPAddress} git.${domain}
130 ${config.networking.primaryIPAddress} meta.${domain}
133 services.sourcehut = {
141 nginx.virtualHost = {
143 sslCertificate = "${tls-cert}/cert.pem";
144 sslCertificateKey = "${tls-cert}/key.pem";
146 postgresql.enable = true;
152 # FIXME: see why it does not seem to activate fully.
153 #enableWorker = true;
159 global-domain = config.networking.domain;
160 service-key = pkgs.writeText "service-key" "8b327279b77e32a3620e2fc9aabce491cc46e7d821fd6713b2a2e650ce114d01";
161 network-key = pkgs.writeText "network-key" "cEEmc30BRBGkgQZcHFksiG7hjc6_dK1XR2Oo5Jb9_nQ=";
163 settings."builds.sr.ht" = {
164 oauth-client-secret = pkgs.writeText "buildsrht-oauth-client-secret" "2260e9c4d9b8dcedcef642860e0504bc";
165 oauth-client-id = "299db9f9c2013170";
167 settings."git.sr.ht" = {
168 oauth-client-secret = pkgs.writeText "gitsrht-oauth-client-secret" "3597288dc2c716e567db5384f493b09d";
169 oauth-client-id = "d07cb713d920702e";
171 settings.webhooks.private-key = pkgs.writeText "webhook-key" "Ra3IjxgFiwG9jxgp4WALQIZw/BMYt30xWiOsqD0J7EA=";
173 smtp-from = "root+hut@${domain}";
174 # WARNING: take care to keep pgp-privkey outside the Nix store in production,
175 # or use LoadCredentialEncrypted=
176 pgp-privkey = toString (pkgs.writeText "sourcehut.pgp-privkey" ''
177 -----BEGIN PGP PRIVATE KEY BLOCK-----
179 lFgEYqDRORYJKwYBBAHaRw8BAQdAehGoy36FUx2OesYm07be2rtLyvR5Pb/ltstd
180 Gk7hYQoAAP9X4oPmxxrHN8LewBpWITdBomNqlHoiP7mI0nz/BOPJHxEktDZuaXhv
181 cy90ZXN0cy9zb3VyY2VodXQgPHJvb3QraHV0QHNvdXJjZWh1dC5sb2NhbGRvbWFp
182 bj6IlwQTFgoAPxYhBPqjgjnL8RHN4JnADNicgXaYm0jJBQJioNE5AhsDBQkDwmcA
183 BgsJCAcDCgUVCgkICwUWAwIBAAIeBQIXgAAKCRDYnIF2mJtIySVCAP9e2nHsVHSi
184 2B1YGZpVG7Xf36vxljmMkbroQy+0gBPwRwEAq+jaiQqlbGhQ7R/HMFcAxBIVsq8h
185 Aw1rngsUd0o3dAicXQRioNE5EgorBgEEAZdVAQUBAQdAXZV2Sd5ZNBVTBbTGavMv
186 D6ORrUh8z7TI/3CsxCE7+yADAQgHAAD/c1RU9xH+V/uI1fE7HIn/zL0LUPpsuce2
187 cH++g4u3kBgTOYh+BBgWCgAmFiEE+qOCOcvxEc3gmcAM2JyBdpibSMkFAmKg0TkC
188 GwwFCQPCZwAACgkQ2JyBdpibSMlKagD/cTre6p1m8QuJ7kwmCFRSz5tBzIuYMMgN
189 xtT7dmS91csA/35fWsOykSiFRojQ7ccCSUTHL7ApF2EbL968tP/D2hIG
191 -----END PGP PRIVATE KEY BLOCK-----
193 pgp-pubkey = pkgs.writeText "sourcehut.pgp-pubkey" ''
194 -----BEGIN PGP PUBLIC KEY BLOCK-----
196 mDMEYqDRORYJKwYBBAHaRw8BAQdAehGoy36FUx2OesYm07be2rtLyvR5Pb/ltstd
197 Gk7hYQq0Nm5peG9zL3Rlc3RzL3NvdXJjZWh1dCA8cm9vdCtodXRAc291cmNlaHV0
198 LmxvY2FsZG9tYWluPoiXBBMWCgA/FiEE+qOCOcvxEc3gmcAM2JyBdpibSMkFAmKg
199 0TkCGwMFCQPCZwAGCwkIBwMKBRUKCQgLBRYDAgEAAh4FAheAAAoJENicgXaYm0jJ
200 JUIA/17acexUdKLYHVgZmlUbtd/fq/GWOYyRuuhDL7SAE/BHAQCr6NqJCqVsaFDt
201 H8cwVwDEEhWyryEDDWueCxR3Sjd0CLg4BGKg0TkSCisGAQQBl1UBBQEBB0BdlXZJ
202 3lk0FVMFtMZq8y8Po5GtSHzPtMj/cKzEITv7IAMBCAeIfgQYFgoAJhYhBPqjgjnL
203 8RHN4JnADNicgXaYm0jJBQJioNE5AhsMBQkDwmcAAAoJENicgXaYm0jJSmoA/3E6
204 3uqdZvELie5MJghUUs+bQcyLmDDIDcbU+3ZkvdXLAP9+X1rDspEohUaI0O3HAklE
205 xy+wKRdhGy/evLT/w9oSBg==
207 -----END PGP PUBLIC KEY BLOCK-----
209 pgp-key-id = "0xFAA38239CBF111CDE099C00CD89C8176989B48C9";
213 networking.firewall.allowedTCPPorts = [ 443 ];
214 security.pki.certificateFiles = [ "${tls-cert}/cert.pem" ];
217 recommendedGzipSettings = true;
218 recommendedOptimisation = true;
219 recommendedTlsSettings = true;
220 recommendedProxySettings = true;
223 services.postgresql = {
226 settings.unix_socket_permissions = "0770";
232 machine.wait_for_unit("multi-user.target")
235 machine.wait_for_unit("metasrht-api.service")
236 machine.wait_for_unit("metasrht.service")
237 machine.wait_for_unit("metasrht-webhooks.service")
238 machine.wait_for_open_port(5000)
239 machine.succeed("curl -sL http://localhost:5000 | grep meta.${domain}")
240 machine.succeed("curl -sL http://meta.${domain} | grep meta.${domain}")
243 machine.wait_for_unit("buildsrht.service")
244 machine.wait_for_open_port(5002)
245 machine.succeed("curl -sL http://localhost:5002 | grep builds.${domain}")
246 #machine.wait_for_unit("buildsrht-worker.service")
249 machine.wait_for_unit("gitsrht-api.service")
250 machine.wait_for_unit("gitsrht.service")
251 machine.wait_for_unit("gitsrht-webhooks.service")
252 machine.succeed("curl -sL http://git.${domain} | grep git.${domain}")