1 diff --git a/nixos/lib/make-options-doc/options-to-docbook.xsl b/nixos/lib/make-options-doc/options-to-docbook.xsl
2 index b9ac2645051..b286f7b5e2c 100644
3 --- a/nixos/lib/make-options-doc/options-to-docbook.xsl
4 +++ b/nixos/lib/make-options-doc/options-to-docbook.xsl
6 <title>Configuration Options</title>
7 <variablelist xml:id="configuration-variable-list">
8 <xsl:for-each select="attrs">
9 - <xsl:variable name="id" select="concat('opt-', str:replace(str:replace(str:replace(attr[@name = 'name']/string/@value, '*', '_'), '<', '_'), '>', '_'))" />
10 + <xsl:variable name="id" select="concat('opt-', str:replace(str:replace(str:replace(str:replace(attr[@name = 'name']/string/@value, '*', '_'), '<', '_'), '>', '_'), ':', '_'))" />
12 <term xlink:href="#{$id}">
13 <xsl:attribute name="xml:id"><xsl:value-of select="$id"/></xsl:attribute>
14 diff --git a/nixos/modules/services/misc/sourcehut/builds.nix b/nixos/modules/services/misc/sourcehut/builds.nix
15 deleted file mode 100644
16 index f806e8c51b9..00000000000
17 --- a/nixos/modules/services/misc/sourcehut/builds.nix
20 -{ config, lib, pkgs, ... }:
24 - cfg = config.services.sourcehut;
26 - rcfg = config.services.redis;
27 - iniKey = "builds.sr.ht";
29 - drv = pkgs.sourcehut.buildsrht;
32 - options.services.sourcehut.builds = {
35 - default = "buildsrht";
37 - User for builds.sr.ht.
45 - Port on which the "builds" module should listen.
49 - database = mkOption {
51 - default = "builds.sr.ht";
53 - PostgreSQL database name for builds.sr.ht.
57 - statePath = mkOption {
59 - default = "${cfg.statePath}/buildsrht";
61 - State path for builds.sr.ht.
65 - enableWorker = mkOption {
69 - Run workers for builds.sr.ht.
74 - type = types.attrsOf (types.attrsOf (types.attrsOf types.package));
76 - example = lib.literalExpression ''(let
77 - # Pinning unstable to allow usage with flakes and limit rebuilds.
78 - pkgs_unstable = builtins.fetchGit {
79 - url = "https://github.com/NixOS/nixpkgs";
80 - rev = "ff96a0fa5635770390b184ae74debea75c3fd534";
81 - ref = "nixos-unstable";
83 - image_from_nixpkgs = pkgs_unstable: (import ("${pkgs.sourcehut.buildsrht}/lib/images/nixos/image.nix") {
84 - pkgs = (import pkgs_unstable {});
88 - nixos.unstable.x86_64 = image_from_nixpkgs pkgs_unstable;
92 - Images for builds.sr.ht. Each package should be distro.release.arch and point to a /nix/store/package/root.img.qcow2.
98 - config = with scfg; let
99 - image_dirs = lib.lists.flatten (
100 - lib.attrsets.mapAttrsToList
102 - lib.attrsets.mapAttrsToList
104 - lib.attrsets.mapAttrsToList
106 - pkgs.runCommand "buildsrht-images" { } ''
107 - mkdir -p $out/${distro}/${rev}/${arch}
108 - ln -s ${image}/*.qcow2 $out/${distro}/${rev}/${arch}/root.img.qcow2
113 - image_dir_pre = pkgs.symlinkJoin {
114 - name = "builds.sr.ht-worker-images-pre";
115 - paths = image_dirs ++ [
116 - "${pkgs.sourcehut.buildsrht}/lib/images"
119 - image_dir = pkgs.runCommand "builds.sr.ht-worker-images" { } ''
120 - mkdir -p $out/images
121 - cp -Lr ${image_dir_pre}/* $out/images
124 - lib.mkIf (cfg.enable && elem "builds" cfg.services) {
128 - isSystemUser = true;
130 - extraGroups = lib.optionals cfg.builds.enableWorker [ "docker" ];
131 - description = "builds.sr.ht user";
140 - services.postgresql = {
141 - authentication = ''
142 - local ${database} ${user} trust
144 - ensureDatabases = [ database ];
148 - ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
155 - "d ${statePath} 0755 ${user} ${user} -"
156 - ] ++ (lib.optionals cfg.builds.enableWorker
157 - [ "d ${statePath}/logs 0775 ${user} ${user} - -" ]
161 - buildsrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey
163 - after = [ "postgresql.service" "network.target" ];
164 - requires = [ "postgresql.service" ];
165 - wantedBy = [ "multi-user.target" ];
167 - description = "builds.sr.ht website service";
169 - serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
171 - # Hack to bypass this hack: https://git.sr.ht/~sircmpwn/core.sr.ht/tree/master/item/srht-update-profiles#L6
172 - } // { preStart = " "; };
174 - buildsrht-worker = {
175 - enable = scfg.enableWorker;
176 - after = [ "postgresql.service" "network.target" ];
177 - requires = [ "postgresql.service" ];
178 - wantedBy = [ "multi-user.target" ];
179 - partOf = [ "buildsrht.service" ];
180 - description = "builds.sr.ht worker service";
181 - path = [ pkgs.openssh pkgs.docker ];
182 - preStart = let qemuPackage = pkgs.qemu_kvm;
184 - if [[ "$(docker images -q qemu:latest 2> /dev/null)" == "" || "$(cat ${statePath}/docker-image-qemu 2> /dev/null || true)" != "${qemuPackage.version}" ]]; then
185 - # Create and import qemu:latest image for docker
187 - pkgs.dockerTools.streamLayeredImage {
190 - contents = [ qemuPackage ];
193 - # Mark down current package version
194 - printf "%s" "${qemuPackage.version}" > ${statePath}/docker-image-qemu
201 - Restart = "always";
203 - serviceConfig.ExecStart = "${pkgs.sourcehut.buildsrht}/bin/builds.sr.ht-worker";
208 - services.sourcehut.settings = {
209 - # URL builds.sr.ht is being served at (protocol://domain)
210 - "builds.sr.ht".origin = mkDefault "http://builds.${cfg.originBase}";
211 - # Address and port to bind the debug server to
212 - "builds.sr.ht".debug-host = mkDefault "0.0.0.0";
213 - "builds.sr.ht".debug-port = mkDefault port;
214 - # Configures the SQLAlchemy connection string for the database.
215 - "builds.sr.ht".connection-string = mkDefault "postgresql:///${database}?user=${user}&host=/var/run/postgresql";
216 - # Set to "yes" to automatically run migrations on package upgrade.
217 - "builds.sr.ht".migrate-on-upgrade = mkDefault "yes";
218 - # builds.sr.ht's OAuth client ID and secret for meta.sr.ht
219 - # Register your client at meta.example.org/oauth
220 - "builds.sr.ht".oauth-client-id = mkDefault null;
221 - "builds.sr.ht".oauth-client-secret = mkDefault null;
222 - # The redis connection used for the celery worker
223 - "builds.sr.ht".redis = mkDefault "redis://${rcfg.bind}:${toString rcfg.port}/3";
224 - # The shell used for ssh
225 - "builds.sr.ht".shell = mkDefault "runner-shell";
226 - # Register the builds.sr.ht dispatcher
227 - "git.sr.ht::dispatch".${builtins.unsafeDiscardStringContext "${pkgs.sourcehut.buildsrht}/bin/buildsrht-keys"} = mkDefault "${user}:${user}";
229 - # Location for build logs, images, and control command
230 - } // lib.attrsets.optionalAttrs scfg.enableWorker {
231 - # Default worker stores logs that are accessible via this address:port
232 - "builds.sr.ht::worker".name = mkDefault "127.0.0.1:5020";
233 - "builds.sr.ht::worker".buildlogs = mkDefault "${scfg.statePath}/logs";
234 - "builds.sr.ht::worker".images = mkDefault "${image_dir}/images";
235 - "builds.sr.ht::worker".controlcmd = mkDefault "${image_dir}/images/control";
236 - "builds.sr.ht::worker".timeout = mkDefault "3m";
239 - services.nginx.virtualHosts."logs.${cfg.originBase}" =
240 - if scfg.enableWorker then {
241 - listen = with builtins; let address = split ":" cfg.settings."builds.sr.ht::worker".name;
242 - in [{ addr = elemAt address 0; port = lib.toInt (elemAt address 2); }];
243 - locations."/logs".root = "${scfg.statePath}";
246 - services.nginx.virtualHosts."builds.${cfg.originBase}" = {
248 - locations."/".proxyPass = "http://${cfg.address}:${toString port}";
249 - locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
250 - locations."/static".root = "${pkgs.sourcehut.buildsrht}/${pkgs.sourcehut.python.sitePackages}/buildsrht";
254 diff --git a/nixos/modules/services/misc/sourcehut/default.nix b/nixos/modules/services/misc/sourcehut/default.nix
255 index c84a75b0ca0..1bd21c278e0 100644
256 --- a/nixos/modules/services/misc/sourcehut/default.nix
257 +++ b/nixos/modules/services/misc/sourcehut/default.nix
259 { config, pkgs, lib, ... }:
263 + inherit (config.services) nginx postfix postgresql redis;
264 + inherit (config.users) users groups;
265 cfg = config.services.sourcehut;
266 - cfgIni = cfg.settings;
267 - settingsFormat = pkgs.formats.ini { };
268 + domain = cfg.settings."sr.ht".global-domain;
269 + settingsFormat = pkgs.formats.ini {
270 + listToValue = concatMapStringsSep "," (generators.mkValueStringDefault {});
272 + if v == null then ""
273 + else generators.mkKeyValueDefault {
275 + if v == true then "yes"
276 + else if v == false then "no"
277 + else generators.mkValueStringDefault {} v;
280 + configIniOfService = srv: settingsFormat.generate "sourcehut-${srv}-config.ini"
281 + # Each service needs access to only a subset of sections (and secrets).
282 + (filterAttrs (k: v: v != null)
283 + (mapAttrs (section: v:
284 + let srvMatch = builtins.match "^([a-z]*)\\.sr\\.ht(::.*)?$" section; in
285 + if srvMatch == null # Include sections shared by all services
286 + || head srvMatch == srv # Include sections for the service being configured
288 + # Enable Web links and integrations between services.
289 + else if tail srvMatch == [ null ] && elem (head srvMatch) cfg.services
291 + inherit (v) origin;
292 + # mansrht crashes without it
293 + oauth-client-id = v.oauth-client-id or null;
295 + # Drop sub-sections of other services
297 + (recursiveUpdate cfg.settings {
298 + # Those paths are mounted using BindPaths= or BindReadOnlyPaths=
299 + # for services needing access to them.
300 + "builds.sr.ht::worker".buildlogs = "/var/log/sourcehut/buildsrht-worker";
301 + "git.sr.ht".post-update-script = "/usr/bin/gitsrht-update-hook";
302 + "git.sr.ht".repos = "/var/lib/sourcehut/gitsrht/repos";
303 + "hg.sr.ht".changegroup-script = "/usr/bin/hgsrht-hook-changegroup";
304 + "hg.sr.ht".repos = "/var/lib/sourcehut/hgsrht/repos";
305 + # Making this a per service option despite being in a global section,
306 + # so that it uses the redis-server used by the service.
307 + "sr.ht".redis-host = cfg.${srv}.redis.host;
309 + commonServiceSettings = srv: {
310 + origin = mkOption {
311 + description = "URL ${srv}.sr.ht is being served at (protocol://domain)";
313 + default = "https://${srv}.${domain}";
314 + defaultText = "https://${srv}.example.com";
316 + debug-host = mkOption {
317 + description = "Address to bind the debug server to.";
318 + type = with types; nullOr str;
321 + debug-port = mkOption {
322 + description = "Port to bind the debug server to.";
323 + type = with types; nullOr str;
326 + connection-string = mkOption {
327 + description = "SQLAlchemy connection string for the database.";
329 + default = "postgresql:///localhost?user=${srv}srht&host=/run/postgresql";
331 + migrate-on-upgrade = mkEnableOption "automatic migrations on package upgrade" // { default = true; };
332 + oauth-client-id = mkOption {
333 + description = "${srv}.sr.ht's OAuth client id for meta.sr.ht.";
336 + oauth-client-secret = mkOption {
337 + description = "${srv}.sr.ht's OAuth client secret for meta.sr.ht.";
339 + apply = s: "<" + toString s;
343 # Specialized python containing all the modules
344 python = pkgs.sourcehut.python.withPackages (ps: with ps; [
347 + # For monitoring Celery: sudo -u listssrht celery --app listssrht.process -b redis+socket:///run/redis-sourcehut/redis.sock?virtual_host=5 flower
352 @@ -19,72 +95,37 @@ let
356 + # Not a python package
361 + mkOptionNullOrStr = description: mkOption {
362 + inherit description;
363 + type = with types; nullOr str;
380 - (mkRemovedOptionModule [ "services" "sourcehut" "nginx" "enable" ] ''
381 - The sourcehut module supports `nginx` as a local reverse-proxy by default and doesn't
382 - support other reverse-proxies officially.
384 - However it's possible to use an alternative reverse-proxy by
387 - * adjusting the relevant settings for server addresses and ports directly
389 - Further details about this can be found in the `Sourcehut`-section of the NixOS-manual.
393 options.services.sourcehut = {
394 - enable = mkOption {
398 - Enable sourcehut - git hosting, continuous integration, mailing list, ticket tracking,
399 - task dispatching, wiki and account management services
402 + enable = mkEnableOption ''
403 + sourcehut - git hosting, continuous integration, mailing list, ticket tracking,
404 + task dispatching, wiki and account management services
407 services = mkOption {
408 - type = types.nonEmptyListOf (types.enum [ "builds" "dispatch" "git" "hub" "hg" "lists" "man" "meta" "paste" "todo" ]);
409 - default = [ "man" "meta" "paste" ];
410 - example = [ "builds" "dispatch" "git" "hub" "hg" "lists" "man" "meta" "paste" "todo" ];
411 + type = with types; listOf (enum
412 + [ "builds" "dispatch" "git" "hg" "hub" "lists" "man" "meta" "pages" "paste" "todo" ]);
413 + defaultText = "locally enabled services";
415 - Services to enable on the sourcehut network.
416 + Services that may be displayed as links in the title bar of the Web interface.
420 - originBase = mkOption {
421 + listenAddress = mkOption {
423 - default = with config.networking; hostName + lib.optionalString (domain != null) ".${domain}";
424 - defaultText = literalExpression ''
425 - with config.networking; hostName + optionalString (domain != null) ".''${domain}"
428 - Host name used by reverse-proxy and for default settings. Will host services at git."''${originBase}". For example: git.sr.ht
432 - address = mkOption {
434 - default = "127.0.0.1";
436 - Address to bind to.
438 + default = "localhost";
439 + description = "Address to bind to.";
443 @@ -97,105 +138,1247 @@ in
447 - statePath = mkOption {
449 - default = "/var/lib/sourcehut";
451 - Root state path for the sourcehut network. If left as the default value
452 - this directory will automatically be created before the sourcehut server
453 - starts, otherwise the sysadmin is responsible for ensuring the
454 - directory exists with appropriate ownership and permissions.
457 + enable = mkEnableOption ''local minio integration'';
461 + enable = mkEnableOption ''local nginx integration'';
462 + virtualHost = mkOption {
463 + type = types.attrs;
465 + description = "Virtual-host configuration merged with all Sourcehut's virtual-hosts.";
470 + enable = mkEnableOption ''local postfix integration'';
474 + enable = mkEnableOption ''local postgresql integration'';
478 + enable = mkEnableOption ''local redis integration in a dedicated redis-server'';
481 settings = mkOption {
482 type = lib.types.submodule {
483 freeformType = settingsFormat.type;
484 + options."sr.ht" = {
485 + global-domain = mkOption {
486 + description = "Global domain name.";
488 + example = "example.com";
490 + environment = mkOption {
491 + description = "Values other than \"production\" adds a banner to each page.";
492 + type = types.enum [ "development" "production" ];
493 + default = "development";
495 + network-key = mkOption {
497 + An absolute file path (which should be outside the Nix-store)
498 + to a secret key to encrypt internal messages with. Use <code>srht-keygen network</code> to
499 + generate this key. It must be consistent between all services and nodes.
502 + apply = s: "<" + toString s;
504 + owner-email = mkOption {
505 + description = "Owner's email.";
507 + default = "contact@example.com";
509 + owner-name = mkOption {
510 + description = "Owner's name.";
512 + default = "John Doe";
514 + site-blurb = mkOption {
515 + description = "Blurb for your site.";
517 + default = "the hacker's forge";
519 + site-info = mkOption {
520 + description = "The top-level info page for your site.";
522 + default = "https://sourcehut.org";
524 + service-key = mkOption {
526 + An absolute file path (which should be outside the Nix-store)
527 + to a key used for encrypting session cookies. Use <code>srht-keygen service</code> to
528 + generate the service key. This must be shared between each node of the same
529 + service (e.g. git1.sr.ht and git2.sr.ht), but different services may use
530 + different keys. If you configure all of your services with the same
531 + config.ini, you may use the same service-key for all of them.
534 + apply = s: "<" + toString s;
536 + site-name = mkOption {
537 + description = "The name of your network of sr.ht-based sites.";
539 + default = "sourcehut";
541 + source-url = mkOption {
542 + description = "The source code for your fork of sr.ht.";
544 + default = "https://git.sr.ht/~sircmpwn/srht";
548 + smtp-host = mkOptionNullOrStr "Outgoing SMTP host.";
549 + smtp-port = mkOption {
550 + description = "Outgoing SMTP port.";
551 + type = with types; nullOr port;
554 + smtp-user = mkOptionNullOrStr "Outgoing SMTP user.";
555 + smtp-password = mkOptionNullOrStr "Outgoing SMTP password.";
556 + smtp-from = mkOptionNullOrStr "Outgoing SMTP FROM.";
557 + error-to = mkOptionNullOrStr "Address receiving application exceptions";
558 + error-from = mkOptionNullOrStr "Address sending application exceptions";
559 + pgp-privkey = mkOptionNullOrStr ''
560 + An absolute file path (which should be outside the Nix-store)
561 + to an OpenPGP private key.
563 + Your PGP key information (DO NOT mix up pub and priv here)
564 + You must remove the password from your secret key, if present.
565 + You can do this with <code>gpg --edit-key [key-id]</code>,
566 + then use the <code>passwd</code> command and do not enter a new password.
568 + pgp-pubkey = mkOptionNullOrStr "OpenPGP public key.";
569 + pgp-key-id = mkOptionNullOrStr "OpenPGP key identifier.";
571 + options.objects = {
572 + s3-upstream = mkOption {
573 + description = "Configure the S3-compatible object storage service.";
574 + type = with types; nullOr str;
577 + s3-access-key = mkOption {
578 + description = "Access key to the S3-compatible object storage service";
579 + type = with types; nullOr str;
582 + s3-secret-key = mkOption {
584 + An absolute file path (which should be outside the Nix-store)
585 + to the secret key of the S3-compatible object storage service.
587 + type = with types; nullOr path;
589 + apply = mapNullable (s: "<" + toString s);
592 + options.webhooks = {
593 + private-key = mkOption {
595 + An absolute file path (which should be outside the Nix-store)
596 + to a base64-encoded Ed25519 key for signing webhook payloads.
597 + This should be consistent for all *.sr.ht sites,
598 + as this key will be used to verify signatures
599 + from other sites in your network.
600 + Use the <code>srht-keygen webhook</code> command to generate a key.
603 + apply = s: "<" + toString s;
607 + options."dispatch.sr.ht" = commonServiceSettings "dispatch" // {
609 + options."dispatch.sr.ht::github" = {
610 + oauth-client-id = mkOptionNullOrStr "OAuth client id.";
611 + oauth-client-secret = mkOptionNullOrStr "OAuth client secret.";
613 + options."dispatch.sr.ht::gitlab" = {
614 + enabled = mkEnableOption "GitLab integration";
615 + canonical-upstream = mkOption {
617 + description = "Canonical upstream.";
618 + default = "gitlab.com";
620 + repo-cache = mkOption {
622 + description = "Repository cache directory.";
623 + default = "./repo-cache";
625 + "gitlab.com" = mkOption {
626 + type = with types; nullOr str;
627 + description = "GitLab id and secret.";
629 + example = "GitLab:application id:secret";
633 + options."builds.sr.ht" = commonServiceSettings "builds" // {
634 + allow-free = mkEnableOption "nonpaying users to submit builds";
636 + description = "The Redis connection used for the Celery worker.";
638 + default = "redis+socket:///run/redis-sourcehut-buildsrht/redis.sock?virtual_host=2";
642 + Scripts used to launch on SSH connection.
643 + <literal>/usr/bin/master-shell</literal> on master,
644 + <literal>/usr/bin/runner-shell</literal> on runner.
645 + If master and worker are on the same system
646 + set to <literal>/usr/bin/runner-shell</literal>.
648 + type = types.enum ["/usr/bin/master-shell" "/usr/bin/runner-shell"];
649 + default = "/usr/bin/master-shell";
652 + options."builds.sr.ht::worker" = {
653 + bind-address = mkOption {
655 + HTTP bind address for serving local build information/monitoring.
658 + default = "localhost:8080";
660 + buildlogs = mkOption {
661 + description = "Path to write build logs.";
663 + default = "/var/log/sourcehut/buildsrht-worker";
667 + Listening address and listening port
668 + of the build runner (with HTTP port if not 80).
671 + default = "localhost:5020";
673 + timeout = mkOption {
675 + Max build duration.
676 + See <link xlink:href="https://golang.org/pkg/time/#ParseDuration"/>.
683 + options."git.sr.ht" = commonServiceSettings "git" // {
684 + outgoing-domain = mkOption {
685 + description = "Outgoing domain.";
687 + default = "https://git.localhost.localdomain";
689 + post-update-script = mkOption {
691 + A post-update script which is installed in every git repo.
692 + This setting is propagated to newer and existing repositories.
695 + default = "${pkgs.sourcehut.gitsrht}/bin/gitsrht-update-hook";
696 + defaultText = "\${pkgs.sourcehut.gitsrht}/bin/gitsrht-update-hook";
700 + Path to git repositories on disk.
701 + If changing the default, you must ensure that
702 + the gitsrht's user as read and write access to it.
705 + default = "/var/lib/sourcehut/gitsrht/repos";
707 + webhooks = mkOption {
708 + description = "The Redis connection used for the webhooks worker.";
710 + default = "redis+socket:///run/redis-sourcehut-gitsrht/redis.sock?virtual_host=1";
713 + options."git.sr.ht::api" = {
714 + internal-ipnet = mkOption {
716 + Set of IP subnets which are permitted to utilize internal API
717 + authentication. This should be limited to the subnets
718 + from which your *.sr.ht services are running.
719 + See <xref linkend="opt-services.sourcehut.listenAddress"/>.
721 + type = with types; listOf str;
722 + default = [ "127.0.0.0/8" "::1/128" ];
726 + options."hg.sr.ht" = commonServiceSettings "hg" // {
727 + changegroup-script = mkOption {
729 + A changegroup script which is installed in every mercurial repo.
730 + This setting is propagated to newer and existing repositories.
733 + default = "${cfg.python}/bin/hgsrht-hook-changegroup";
734 + defaultText = "\${cfg.python}/bin/hgsrht-hook-changegroup";
738 + Path to mercurial repositories on disk.
739 + If changing the default, you must ensure that
740 + the hgsrht's user as read and write access to it.
743 + default = "/var/lib/sourcehut/hgsrht/repos";
745 + srhtext = mkOptionNullOrStr ''
746 + Path to the srht mercurial extension
747 + (defaults to where the hgsrht code is)
749 + clone_bundle_threshold = mkOption {
750 + description = ".hg/store size (in MB) past which the nightly job generates clone bundles.";
751 + type = types.ints.unsigned;
754 + hg_ssh = mkOption {
755 + description = "Path to hg-ssh (if not in $PATH).";
757 + default = "${pkgs.mercurial}/bin/hg-ssh";
758 + defaultText = "\${pkgs.mercurial}/bin/hg-ssh";
760 + webhooks = mkOption {
761 + description = "The Redis connection used for the webhooks worker.";
763 + default = "redis+socket:///run/redis-sourcehut-hgsrht/redis.sock?virtual_host=1";
767 + options."hub.sr.ht" = commonServiceSettings "hub" // {
770 + options."lists.sr.ht" = commonServiceSettings "lists" // {
771 + allow-new-lists = mkEnableOption "Allow creation of new lists.";
772 + notify-from = mkOption {
773 + description = "Outgoing email for notifications generated by users.";
775 + default = "lists-notify@localhost.localdomain";
777 + posting-domain = mkOption {
778 + description = "Posting domain.";
780 + default = "lists.localhost.localdomain";
783 + description = "The Redis connection used for the Celery worker.";
785 + default = "redis+socket:///run/redis-sourcehut-listssrht/redis.sock?virtual_host=2";
787 + webhooks = mkOption {
788 + description = "The Redis connection used for the webhooks worker.";
790 + default = "redis+socket:///run/redis-sourcehut-listssrht/redis.sock?virtual_host=1";
793 + options."lists.sr.ht::worker" = {
794 + reject-mimetypes = mkOption {
796 + Comma-delimited list of Content-Types to reject. Messages with Content-Types
797 + included in this list are rejected. Multipart messages are always supported,
798 + and each part is checked against this list.
800 + Uses fnmatch for wildcard expansion.
802 + type = with types; listOf str;
803 + default = ["text/html"];
805 + reject-url = mkOption {
806 + description = "Reject URL.";
808 + default = "https://man.sr.ht/lists.sr.ht/etiquette.md";
812 + Path for the lmtp daemon's unix socket. Direct incoming mail to this socket.
813 + Alternatively, specify IP:PORT and an SMTP server will be run instead.
816 + default = "/tmp/lists.sr.ht-lmtp.sock";
818 + sock-group = mkOption {
820 + The lmtp daemon will make the unix socket group-read/write
821 + for users in this group.
824 + default = "postfix";
828 + options."man.sr.ht" = commonServiceSettings "man" // {
831 + options."meta.sr.ht" =
832 + removeAttrs (commonServiceSettings "meta")
833 + ["oauth-client-id" "oauth-client-secret"] // {
834 + api-origin = mkOption {
835 + description = "Origin URL for API, 100 more than web.";
837 + default = "http://${cfg.listenAddress}:${toString (cfg.meta.port + 100)}";
838 + defaultText = ''http://<xref linkend="opt-services.sourcehut.listenAddress"/>:''${toString (<xref linkend="opt-services.sourcehut.meta.port"/> + 100)}'';
840 + webhooks = mkOption {
841 + description = "The Redis connection used for the webhooks worker.";
843 + default = "redis+socket:///run/redis-sourcehut-metasrht/redis.sock?virtual_host=1";
845 + welcome-emails = mkEnableOption "sending stock sourcehut welcome emails after signup";
847 + options."meta.sr.ht::api" = {
848 + internal-ipnet = mkOption {
850 + Set of IP subnets which are permitted to utilize internal API
851 + authentication. This should be limited to the subnets
852 + from which your *.sr.ht services are running.
853 + See <xref linkend="opt-services.sourcehut.listenAddress"/>.
855 + type = with types; listOf str;
856 + default = [ "127.0.0.0/8" "::1/128" ];
859 + options."meta.sr.ht::aliases" = mkOption {
860 + description = "Aliases for the client IDs of commonly used OAuth clients.";
861 + type = with types; attrsOf int;
863 + example = { "git.sr.ht" = 12345; };
865 + options."meta.sr.ht::billing" = {
866 + enabled = mkEnableOption "the billing system";
867 + stripe-public-key = mkOptionNullOrStr "Public key for Stripe. Get your keys at https://dashboard.stripe.com/account/apikeys";
868 + stripe-secret-key = mkOptionNullOrStr ''
869 + An absolute file path (which should be outside the Nix-store)
870 + to a secret key for Stripe. Get your keys at https://dashboard.stripe.com/account/apikeys
872 + apply = mapNullable (s: "<" + toString s);
875 + options."meta.sr.ht::settings" = {
876 + registration = mkEnableOption "public registration";
877 + onboarding-redirect = mkOption {
878 + description = "Where to redirect new users upon registration.";
880 + default = "https://meta.localhost.localdomain";
882 + user-invites = mkOption {
884 + How many invites each user is issued upon registration
885 + (only applicable if open registration is disabled).
887 + type = types.ints.unsigned;
892 + options."pages.sr.ht" = commonServiceSettings "pages" // {
893 + gemini-certs = mkOption {
895 + An absolute file path (which should be outside the Nix-store)
896 + to Gemini certificates.
898 + type = with types; nullOr path;
901 + max-site-size = mkOption {
902 + description = "Maximum size of any given site (post-gunzip), in MiB.";
906 + user-domain = mkOption {
908 + Configures the user domain, if enabled.
909 + All users are given <username>.this.domain.
911 + type = with types; nullOr str;
915 + options."pages.sr.ht::api" = {
916 + internal-ipnet = mkOption {
918 + Set of IP subnets which are permitted to utilize internal API
919 + authentication. This should be limited to the subnets
920 + from which your *.sr.ht services are running.
921 + See <xref linkend="opt-services.sourcehut.listenAddress"/>.
923 + type = with types; listOf str;
924 + default = [ "127.0.0.0/8" "::1/128" ];
928 + options."paste.sr.ht" = commonServiceSettings "paste" // {
931 + options."todo.sr.ht" = commonServiceSettings "todo" // {
932 + notify-from = mkOption {
933 + description = "Outgoing email for notifications generated by users.";
935 + default = "todo-notify@localhost.localdomain";
937 + webhooks = mkOption {
938 + description = "The Redis connection used for the webhooks worker.";
940 + default = "redis+socket:///run/redis-sourcehut-todosrht/redis.sock?virtual_host=1";
943 + options."todo.sr.ht::mail" = {
944 + posting-domain = mkOption {
945 + description = "Posting domain.";
947 + default = "todo.localhost.localdomain";
951 + Path for the lmtp daemon's unix socket. Direct incoming mail to this socket.
952 + Alternatively, specify IP:PORT and an SMTP server will be run instead.
955 + default = "/tmp/todo.sr.ht-lmtp.sock";
957 + sock-group = mkOption {
959 + The lmtp daemon will make the unix socket group-read/write
960 + for users in this group.
963 + default = "postfix";
969 The configuration for the sourcehut network.
974 - config = mkIf cfg.enable {
978 - assertion = with cfgIni.webhooks; private-key != null && stringLength private-key == 44;
979 - message = "The webhook's private key must be defined and of a 44 byte length.";
982 + enableWorker = mkEnableOption ''
983 + worker for builds.sr.ht
986 - assertion = hasAttrByPath [ "meta.sr.ht" "origin" ] cfgIni && cfgIni."meta.sr.ht".origin != null;
987 - message = "meta.sr.ht's origin must be defined.";
991 + For smaller deployments, job runners can be installed alongside the master server
992 + but even if you only build your own software, integration with other services
993 + may cause you to run untrusted builds
994 + (e.g. automatic testing of patches via listssrht).
995 + See <link xlink:href="https://man.sr.ht/builds.sr.ht/configuration.md#security-model"/>.
999 - virtualisation.docker.enable = true;
1000 - environment.etc."sr.ht/config.ini".source =
1001 - settingsFormat.generate "sourcehut-config.ini" (mapAttrsRecursive
1003 - path: v: if v == null then "" else v
1006 + images = mkOption {
1007 + type = with types; attrsOf (attrsOf (attrsOf package));
1009 + example = lib.literalExpression ''(let
1010 + # Pinning unstable to allow usage with flakes and limit rebuilds.
1011 + pkgs_unstable = builtins.fetchGit {
1012 + url = "https://github.com/NixOS/nixpkgs";
1013 + rev = "ff96a0fa5635770390b184ae74debea75c3fd534";
1014 + ref = "nixos-unstable";
1016 + image_from_nixpkgs = (import ("${pkgs.sourcehut.buildsrht}/lib/images/nixos/image.nix") {
1017 + pkgs = (import pkgs_unstable {});
1021 + nixos.unstable.x86_64 = image_from_nixpkgs;
1025 + Images for builds.sr.ht. Each package should be distro.release.arch and point to a /nix/store/package/root.img.qcow2.
1030 - environment.systemPackages = [ pkgs.sourcehut.coresrht ];
1032 + package = mkOption {
1033 + type = types.package;
1034 + default = pkgs.git;
1035 + example = literalExpression "pkgs.gitFull";
1037 + Git package for git.sr.ht. This can help silence collisions.
1040 + fcgiwrap.preforkProcess = mkOption {
1041 + description = "Number of fcgiwrap processes to prefork.";
1047 - # PostgreSQL server
1048 - services.postgresql.enable = mkOverride 999 true;
1050 - services.postfix.enable = mkOverride 999 true;
1052 - services.cron.enable = mkOverride 999 true;
1054 - services.redis.enable = mkOverride 999 true;
1055 - services.redis.bind = mkOverride 999 "127.0.0.1";
1057 + package = mkOption {
1058 + type = types.package;
1059 + default = pkgs.mercurial;
1061 + Mercurial package for hg.sr.ht. This can help silence collisions.
1064 + cloneBundles = mkOption {
1065 + type = types.bool;
1068 + Generate clonebundles (which require more disk space but dramatically speed up cloning large repositories).
1073 - services.sourcehut.settings = {
1074 - # The name of your network of sr.ht-based sites
1075 - "sr.ht".site-name = mkDefault "sourcehut";
1076 - # The top-level info page for your site
1077 - "sr.ht".site-info = mkDefault "https://sourcehut.org";
1078 - # {{ site-name }}, {{ site-blurb }}
1079 - "sr.ht".site-blurb = mkDefault "the hacker's forge";
1080 - # If this != production, we add a banner to each page
1081 - "sr.ht".environment = mkDefault "development";
1082 - # Contact information for the site owners
1083 - "sr.ht".owner-name = mkDefault "Drew DeVault";
1084 - "sr.ht".owner-email = mkDefault "sir@cmpwn.com";
1085 - # The source code for your fork of sr.ht
1086 - "sr.ht".source-url = mkDefault "https://git.sr.ht/~sircmpwn/srht";
1087 - # A secret key to encrypt session cookies with
1088 - "sr.ht".secret-key = mkDefault null;
1089 - "sr.ht".global-domain = mkDefault null;
1091 - # Outgoing SMTP settings
1092 - mail.smtp-host = mkDefault null;
1093 - mail.smtp-port = mkDefault null;
1094 - mail.smtp-user = mkDefault null;
1095 - mail.smtp-password = mkDefault null;
1096 - mail.smtp-from = mkDefault null;
1097 - # Application exceptions are emailed to this address
1098 - mail.error-to = mkDefault null;
1099 - mail.error-from = mkDefault null;
1100 - # Your PGP key information (DO NOT mix up pub and priv here)
1101 - # You must remove the password from your secret key, if present.
1102 - # You can do this with gpg --edit-key [key-id], then use the passwd
1103 - # command and do not enter a new password.
1104 - mail.pgp-privkey = mkDefault null;
1105 - mail.pgp-pubkey = mkDefault null;
1106 - mail.pgp-key-id = mkDefault null;
1108 - # base64-encoded Ed25519 key for signing webhook payloads. This should be
1109 - # consistent for all *.sr.ht sites, as we'll use this key to verify signatures
1110 - # from other sites in your network.
1112 - # Use the srht-webhook-keygen command to generate a key.
1113 - webhooks.private-key = mkDefault null;
1116 + extraArgs = mkOption {
1117 + type = with types; listOf str;
1118 + default = [ "--loglevel DEBUG" "--pool eventlet" "--without-heartbeat" ];
1119 + description = "Extra arguments passed to the Celery responsible for processing mails.";
1121 + celeryConfig = mkOption {
1122 + type = types.lines;
1124 + description = "Content of the <literal>celeryconfig.py</literal> used by the Celery of <literal>listssrht-process</literal>.";
1130 + config = mkIf cfg.enable (mkMerge [
1132 + environment.systemPackages = [ pkgs.sourcehut.coresrht ];
1134 + services.sourcehut.settings = {
1135 + "git.sr.ht".outgoing-domain = mkDefault "https://git.${domain}";
1136 + "lists.sr.ht".notify-from = mkDefault "lists-notify@${domain}";
1137 + "lists.sr.ht".posting-domain = mkDefault "lists.${domain}";
1138 + "meta.sr.ht::settings".onboarding-redirect = mkDefault "https://meta.${domain}";
1139 + "todo.sr.ht".notify-from = mkDefault "todo-notify@${domain}";
1140 + "todo.sr.ht::mail".posting-domain = mkDefault "todo.${domain}";
1143 + (mkIf cfg.postgresql.enable {
1145 + { assertion = postgresql.enable;
1146 + message = "postgresql must be enabled and configured";
1150 + (mkIf cfg.postfix.enable {
1152 + { assertion = postfix.enable;
1153 + message = "postfix must be enabled and configured";
1156 + # Needed for sharing the LMTP sockets with JoinsNamespaceOf=
1157 + systemd.services.postfix.serviceConfig.PrivateTmp = true;
1159 + (mkIf cfg.redis.enable {
1160 + services.redis.vmOverCommit = mkDefault true;
1162 + (mkIf cfg.nginx.enable {
1164 + { assertion = nginx.enable;
1165 + message = "nginx must be enabled and configured";
1168 + # For proxyPass= in virtual-hosts for Sourcehut services.
1169 + services.nginx.recommendedProxySettings = mkDefault true;
1171 + (mkIf (cfg.builds.enable || cfg.git.enable || cfg.hg.enable) {
1172 + services.openssh = {
1173 + # Note that sshd will continue to honor AuthorizedKeysFile.
1174 + # Note that you may want automatically rotate
1175 + # or link to /dev/null the following log files:
1176 + # - /var/log/gitsrht-dispatch
1177 + # - /var/log/{build,git,hg}srht-keys
1178 + # - /var/log/{git,hg}srht-shell
1179 + # - /var/log/gitsrht-update-hook
1180 + authorizedKeysCommand = ''/etc/ssh/sourcehut/subdir/srht-dispatch "%u" "%h" "%t" "%k"'';
1181 + # srht-dispatch will setuid/setgid according to [git.sr.ht::dispatch]
1182 + authorizedKeysCommandUser = "root";
1184 + PermitUserEnvironment SRHT_*
1187 + environment.etc."ssh/sourcehut/config.ini".source =
1188 + settingsFormat.generate "sourcehut-dispatch-config.ini"
1189 + (filterAttrs (k: v: k == "git.sr.ht::dispatch")
1191 + environment.etc."ssh/sourcehut/subdir/srht-dispatch" = {
1192 + # sshd_config(5): The program must be owned by root, not writable by group or others
1194 + source = pkgs.writeShellScript "srht-dispatch" ''
1196 + cd /etc/ssh/sourcehut/subdir
1197 + ${cfg.python}/bin/gitsrht-dispatch "$@"
1200 + systemd.services.sshd = {
1201 + #path = optional cfg.git.enable [ cfg.git.package ];
1203 + BindReadOnlyPaths =
1204 + # Note that those /usr/bin/* paths are hardcoded in multiple places in *.sr.ht,
1205 + # for instance to get the user from the [git.sr.ht::dispatch] settings.
1206 + # *srht-keys needs to:
1207 + # - access a redis-server in [sr.ht] redis-host,
1208 + # - access the PostgreSQL server in [*.sr.ht] connection-string,
1209 + # - query metasrht-api (through the HTTP API).
1210 + # Using this has the side effect of creating empty files in /usr/bin/
1211 + optionals cfg.builds.enable [
1212 + "${pkgs.writeShellScript "buildsrht-keys-wrapper" ''
1214 + cd /run/sourcehut/buildsrht/subdir
1216 + exec -a "$0" ${pkgs.sourcehut.buildsrht}/bin/buildsrht-keys "$@"
1217 + ''}:/usr/bin/buildsrht-keys"
1218 + "${pkgs.sourcehut.buildsrht}/bin/master-shell:/usr/bin/master-shell"
1219 + "${pkgs.sourcehut.buildsrht}/bin/runner-shell:/usr/bin/runner-shell"
1221 + optionals cfg.git.enable [
1222 + # /path/to/gitsrht-keys calls /path/to/gitsrht-shell,
1223 + # or [git.sr.ht] shell= if set.
1224 + "${pkgs.writeShellScript "gitsrht-keys-wrapper" ''
1226 + cd /run/sourcehut/gitsrht/subdir
1228 + exec -a "$0" ${pkgs.sourcehut.gitsrht}/bin/gitsrht-keys "$@"
1229 + ''}:/usr/bin/gitsrht-keys"
1230 + "${pkgs.writeShellScript "gitsrht-shell-wrapper" ''
1232 + cd /run/sourcehut/gitsrht/subdir
1234 + exec -a "$0" ${pkgs.sourcehut.gitsrht}/bin/gitsrht-shell "$@"
1235 + ''}:/usr/bin/gitsrht-shell"
1236 + "${pkgs.writeShellScript "gitsrht-update-hook" ''
1238 + test -e "''${PWD%/*}"/config.ini ||
1239 + # Git hooks are run relative to their repository's directory,
1240 + # but gitsrht-update-hook looks up ../config.ini
1241 + ln -s /run/sourcehut/gitsrht/config.ini "''${PWD%/*}"/config.ini
1242 + # hooks/post-update calls /usr/bin/gitsrht-update-hook as hooks/stage-3
1243 + # but this wrapper being a bash script, it overrides $0 with /usr/bin/gitsrht-update-hook
1244 + # hence this hack to put hooks/stage-3 back into gitsrht-update-hook's $0
1245 + if test "''${STAGE3:+set}"
1248 + exec -a hooks/stage-3 ${pkgs.sourcehut.gitsrht}/bin/gitsrht-update-hook "$@"
1252 + exec -a "$0" ${pkgs.sourcehut.gitsrht}/bin/gitsrht-update-hook "$@"
1254 + ''}:/usr/bin/gitsrht-update-hook"
1256 + optionals cfg.hg.enable [
1257 + # /path/to/hgsrht-keys calls /path/to/hgsrht-shell,
1258 + # or [hg.sr.ht] shell= if set.
1259 + "${pkgs.writeShellScript "hgsrht-keys-wrapper" ''
1261 + cd /run/sourcehut/hgsrht/subdir
1263 + exec -a "$0" ${pkgs.sourcehut.hgsrht}/bin/hgsrht-keys "$@"
1264 + ''}:/usr/bin/hgsrht-keys"
1265 + "${pkgs.writeShellScript "hgsrht-shell-wrapper" ''
1267 + cd /run/sourcehut/hgsrht/subdir
1269 + exec -a "$0" ${pkgs.sourcehut.hgsrht}/bin/hgsrht-shell "$@"
1270 + ''}:/usr/bin/hgsrht-shell"
1271 + # Mercurial's changegroup hooks are run relative to their repository's directory,
1272 + # but hgsrht-hook-changegroup looks up ./config.ini
1273 + "${pkgs.writeShellScript "hgsrht-hook-changegroup" ''
1275 + test -e "''$PWD"/config.ini ||
1276 + ln -s /run/sourcehut/hgsrht/config.ini "''$PWD"/config.ini
1278 + exec -a "$0" ${cfg.python}/bin/hgsrht-hook-changegroup "$@"
1279 + ''}:/usr/bin/hgsrht-hook-changegroup"
1288 + (import ./service.nix "builds" {
1289 + inherit configIniOfService;
1290 + srvsrht = "buildsrht";
1292 + # TODO: a celery worker on the master and worker are apparently needed
1293 + extraServices.buildsrht-worker = let
1294 + qemuPackage = pkgs.qemu_kvm;
1295 + serviceName = "buildsrht-worker";
1296 + statePath = "/var/lib/sourcehut/${serviceName}";
1297 + in mkIf cfg.builds.enableWorker {
1298 + path = [ pkgs.openssh pkgs.docker ];
1301 + if test -z "$(docker images -q qemu:latest 2>/dev/null)" \
1302 + || test "$(cat ${statePath}/docker-image-qemu)" != "${qemuPackage.version}"
1304 + # Create and import qemu:latest image for docker
1305 + ${pkgs.dockerTools.streamLayeredImage {
1308 + contents = [ qemuPackage ];
1310 + # Mark down current package version
1311 + echo '${qemuPackage.version}' >${statePath}/docker-image-qemu
1315 + ExecStart = "${pkgs.sourcehut.buildsrht}/bin/builds.sr.ht-worker";
1316 + BindPaths = [ cfg.settings."builds.sr.ht::worker".buildlogs ];
1317 + LogsDirectory = [ "sourcehut/${serviceName}" ];
1318 + RuntimeDirectory = [ "sourcehut/${serviceName}/subdir" ];
1319 + StateDirectory = [ "sourcehut/${serviceName}" ];
1320 + TimeoutStartSec = "1800s";
1321 + # builds.sr.ht-worker looks up ../config.ini
1322 + WorkingDirectory = "-"+"/run/sourcehut/${serviceName}/subdir";
1326 + image_dirs = flatten (
1327 + mapAttrsToList (distro: revs:
1328 + mapAttrsToList (rev: archs:
1329 + mapAttrsToList (arch: image:
1330 + pkgs.runCommand "buildsrht-images" { } ''
1331 + mkdir -p $out/${distro}/${rev}/${arch}
1332 + ln -s ${image}/*.qcow2 $out/${distro}/${rev}/${arch}/root.img.qcow2
1336 + ) cfg.builds.images
1338 + image_dir_pre = pkgs.symlinkJoin {
1339 + name = "builds.sr.ht-worker-images-pre";
1340 + paths = image_dirs;
1341 + # FIXME: not working, apparently because ubuntu/latest is a broken link
1342 + # ++ [ "${pkgs.sourcehut.buildsrht}/lib/images" ];
1344 + image_dir = pkgs.runCommand "builds.sr.ht-worker-images" { } ''
1345 + mkdir -p $out/images
1346 + cp -Lr ${image_dir_pre}/* $out/images
1350 + users.users.${cfg.builds.user}.shell = pkgs.bash;
1352 + virtualisation.docker.enable = true;
1354 + services.sourcehut.settings = mkMerge [
1355 + { # Note that git.sr.ht::dispatch is not a typo,
1356 + # gitsrht-dispatch always use this section
1357 + "git.sr.ht::dispatch"."/usr/bin/buildsrht-keys" =
1358 + mkDefault "${cfg.builds.user}:${cfg.builds.group}";
1360 + (mkIf cfg.builds.enableWorker {
1361 + "builds.sr.ht::worker".shell = "/usr/bin/runner-shell";
1362 + "builds.sr.ht::worker".images = mkDefault "${image_dir}/images";
1363 + "builds.sr.ht::worker".controlcmd = mkDefault "${image_dir}/images/control";
1367 + (mkIf cfg.builds.enableWorker {
1369 + docker.members = [ cfg.builds.user ];
1372 + (mkIf (cfg.builds.enableWorker && cfg.nginx.enable) {
1373 + # Allow nginx access to buildlogs
1374 + users.users.${nginx.user}.extraGroups = [ cfg.builds.group ];
1375 + systemd.services.nginx = {
1376 + serviceConfig.BindReadOnlyPaths = [ cfg.settings."builds.sr.ht::worker".buildlogs ];
1378 + services.nginx.virtualHosts."logs.${domain}" = mkMerge [ {
1379 + /* FIXME: is a listen needed?
1380 + listen = with builtins;
1381 + # FIXME: not compatible with IPv6
1382 + let address = split ":" cfg.settings."builds.sr.ht::worker".name; in
1383 + [{ addr = elemAt address 0; port = lib.toInt (elemAt address 2); }];
1385 + locations."/logs/".alias = cfg.settings."builds.sr.ht::worker".buildlogs + "/";
1386 + } cfg.nginx.virtualHost ];
1391 + (import ./service.nix "dispatch" {
1392 + inherit configIniOfService;
1396 + (import ./service.nix "git" (let
1398 + path = [ cfg.git.package ];
1399 + serviceConfig.BindPaths = [ "${cfg.settings."git.sr.ht".repos}:/var/lib/sourcehut/gitsrht/repos" ];
1402 + inherit configIniOfService;
1403 + mainService = mkMerge [ baseService {
1404 + serviceConfig.StateDirectory = [ "sourcehut/gitsrht" "sourcehut/gitsrht/repos" ];
1405 + preStart = mkIf (!versionAtLeast config.system.stateVersion "22.05") (mkBefore ''
1406 + # Fix Git hooks of repositories pre-dating https://github.com/NixOS/nixpkgs/pull/133984
1410 + for h in /var/lib/sourcehut/gitsrht/repos/~*/*/hooks/{pre-receive,update,post-update}
1411 + do ln -fnsv /usr/bin/gitsrht-update-hook "$h"; done
1417 + extraTimers.gitsrht-periodic = {
1418 + service = baseService;
1419 + timerConfig.OnCalendar = ["*:0/20"];
1421 + extraConfig = mkMerge [
1423 + # https://stackoverflow.com/questions/22314298/git-push-results-in-fatal-protocol-error-bad-line-length-character-this
1424 + # Probably could use gitsrht-shell if output is restricted to just parameters...
1425 + users.users.${cfg.git.user}.shell = pkgs.bash;
1426 + services.sourcehut.settings = {
1427 + "git.sr.ht::dispatch"."/usr/bin/gitsrht-keys" =
1428 + mkDefault "${cfg.git.user}:${cfg.git.group}";
1430 + systemd.services.sshd = baseService;
1432 + (mkIf cfg.nginx.enable {
1433 + services.nginx.virtualHosts."git.${domain}" = {
1434 + locations."/authorize" = {
1435 + proxyPass = "http://${cfg.listenAddress}:${toString cfg.git.port}";
1437 + proxy_pass_request_body off;
1438 + proxy_set_header Content-Length "";
1439 + proxy_set_header X-Original-URI $request_uri;
1442 + locations."~ ^/([^/]+)/([^/]+)/(HEAD|info/refs|objects/info/.*|git-upload-pack).*$" = {
1443 + root = "/var/lib/sourcehut/gitsrht/repos";
1445 + GIT_HTTP_EXPORT_ALL = "";
1446 + GIT_PROJECT_ROOT = "$document_root";
1447 + PATH_INFO = "$uri";
1448 + SCRIPT_FILENAME = "${cfg.git.package}/bin/git-http-backend";
1451 + auth_request /authorize;
1452 + fastcgi_read_timeout 500s;
1453 + fastcgi_pass unix:/run/gitsrht-fcgiwrap.sock;
1458 + systemd.sockets.gitsrht-fcgiwrap = {
1459 + before = [ "nginx.service" ];
1460 + wantedBy = [ "sockets.target" "gitsrht.service" ];
1461 + # This path remains accessible to nginx.service, which has no RootDirectory=
1462 + socketConfig.ListenStream = "/run/gitsrht-fcgiwrap.sock";
1463 + socketConfig.SocketUser = nginx.user;
1464 + socketConfig.SocketMode = "600";
1468 + extraServices.gitsrht-fcgiwrap = mkIf cfg.nginx.enable {
1470 + # Socket is passed by gitsrht-fcgiwrap.socket
1471 + ExecStart = "${pkgs.fcgiwrap}/sbin/fcgiwrap -c ${toString cfg.git.fcgiwrap.preforkProcess}";
1472 + # No need for config.ini
1473 + ExecStartPre = mkForce [];
1475 + DynamicUser = true;
1476 + BindReadOnlyPaths = [ "${cfg.settings."git.sr.ht".repos}:/var/lib/sourcehut/gitsrht/repos" ];
1477 + IPAddressDeny = "any";
1478 + InaccessiblePaths = [ "-+/run/postgresql" "-+/run/redis-sourcehut" ];
1479 + PrivateNetwork = true;
1480 + RestrictAddressFamilies = mkForce [ "none" ];
1481 + SystemCallFilter = mkForce [
1483 + "~@aio" "~@keyring" "~@memlock" "~@privileged" "~@resources" "~@setuid"
1484 + # @timer is needed for alarm()
1490 + (import ./service.nix "hg" (let
1492 + path = [ cfg.hg.package ];
1493 + serviceConfig.BindPaths = [ "${cfg.settings."hg.sr.ht".repos}:/var/lib/sourcehut/hgsrht/repos" ];
1496 + inherit configIniOfService;
1497 + mainService = mkMerge [ baseService {
1498 + serviceConfig.StateDirectory = [ "sourcehut/hgsrht" "sourcehut/hgsrht/repos" ];
1502 + extraTimers.hgsrht-periodic = {
1503 + service = baseService;
1504 + timerConfig.OnCalendar = ["*:0/20"];
1506 + extraTimers.hgsrht-clonebundles = mkIf cfg.hg.cloneBundles {
1507 + service = baseService;
1508 + timerConfig.OnCalendar = ["daily"];
1509 + timerConfig.AccuracySec = "1h";
1511 + extraConfig = mkMerge [
1513 + users.users.${cfg.hg.user}.shell = pkgs.bash;
1514 + services.sourcehut.settings = {
1515 + # Note that git.sr.ht::dispatch is not a typo,
1516 + # gitsrht-dispatch always uses this section.
1517 + "git.sr.ht::dispatch"."/usr/bin/hgsrht-keys" =
1518 + mkDefault "${cfg.hg.user}:${cfg.hg.group}";
1520 + systemd.services.sshd = baseService;
1522 + (mkIf cfg.nginx.enable {
1523 + # Allow nginx access to repositories
1524 + users.users.${nginx.user}.extraGroups = [ cfg.hg.group ];
1525 + services.nginx.virtualHosts."hg.${domain}" = {
1526 + locations."/authorize" = {
1527 + proxyPass = "http://${cfg.listenAddress}:${toString cfg.hg.port}";
1529 + proxy_pass_request_body off;
1530 + proxy_set_header Content-Length "";
1531 + proxy_set_header X-Original-URI $request_uri;
1534 + # Let clients reach pull bundles. We don't really need to lock this down even for
1535 + # private repos because the bundles are named after the revision hashes...
1536 + # so someone would need to know or guess a SHA value to download anything.
1537 + # TODO: proxyPass to an hg serve service?
1538 + locations."~ ^/[~^][a-z0-9_]+/[a-zA-Z0-9_.-]+/\\.hg/bundles/.*$" = {
1539 + root = "/var/lib/nginx/hgsrht/repos";
1541 + auth_request /authorize;
1546 + systemd.services.nginx = {
1547 + serviceConfig.BindReadOnlyPaths = [ "${cfg.settings."hg.sr.ht".repos}:/var/lib/nginx/hgsrht/repos" ];
1553 + (import ./service.nix "hub" {
1554 + inherit configIniOfService;
1557 + services.nginx = mkIf cfg.nginx.enable {
1558 + virtualHosts."hub.${domain}" = mkMerge [ {
1559 + serverAliases = [ domain ];
1560 + } cfg.nginx.virtualHost ];
1565 + (import ./service.nix "lists" (let
1566 + srvsrht = "listssrht";
1568 + inherit configIniOfService;
1571 + # Receive the mail from Postfix and enqueue them into Redis and PostgreSQL
1572 + extraServices.listssrht-lmtp = {
1573 + wants = [ "postfix.service" ];
1574 + unitConfig.JoinsNamespaceOf = optional cfg.postfix.enable "postfix.service";
1575 + serviceConfig.ExecStart = "${cfg.python}/bin/listssrht-lmtp";
1576 + # Avoid crashing: os.chown(sock, os.getuid(), sock_gid)
1577 + serviceConfig.PrivateUsers = mkForce false;
1579 + # Dequeue the mails from Redis and dispatch them
1580 + extraServices.listssrht-process = {
1583 + cp ${pkgs.writeText "${srvsrht}-webhooks-celeryconfig.py" cfg.lists.process.celeryConfig} \
1584 + /run/sourcehut/${srvsrht}-webhooks/celeryconfig.py
1586 + ExecStart = "${cfg.python}/bin/celery --app listssrht.process worker --hostname listssrht-process@%%h " + concatStringsSep " " cfg.lists.process.extraArgs;
1587 + # Avoid crashing: os.getloadavg()
1588 + ProcSubset = mkForce "all";
1591 + extraConfig = mkIf cfg.postfix.enable {
1592 + users.groups.${postfix.group}.members = [ cfg.lists.user ];
1593 + services.sourcehut.settings."lists.sr.ht::mail".sock-group = postfix.group;
1594 + services.postfix = {
1595 + destination = [ "lists.${domain}" ];
1596 + # FIXME: an accurate recipient list should be queried
1597 + # from the lists.sr.ht PostgreSQL database to avoid backscattering.
1598 + # But usernames are unfortunately not in that database but in meta.sr.ht.
1599 + # Note that two syntaxes are allowed:
1600 + # - ~username/list-name@lists.${domain}
1601 + # - u.username.list-name@lists.${domain}
1602 + localRecipients = [ "@lists.${domain}" ];
1604 + lists.${domain} lmtp:unix:${cfg.settings."lists.sr.ht::worker".sock}
1610 + (import ./service.nix "man" {
1611 + inherit configIniOfService;
1615 + (import ./service.nix "meta" {
1616 + inherit configIniOfService;
1619 + extraServices.metasrht-api = {
1620 + serviceConfig.Restart = "always";
1621 + serviceConfig.RestartSec = "2s";
1622 + preStart = "set -x\n" + concatStringsSep "\n\n" (attrValues (mapAttrs (k: s:
1623 + let srvMatch = builtins.match "^([a-z]*)\\.sr\\.ht$" k;
1624 + srv = head srvMatch;
1626 + # Configure client(s) as "preauthorized"
1627 + optionalString (srvMatch != null && cfg.${srv}.enable && ((s.oauth-client-id or null) != null)) ''
1628 + # Configure ${srv}'s OAuth client as "preauthorized"
1629 + ${postgresql.package}/bin/psql '${cfg.settings."meta.sr.ht".connection-string}' \
1630 + -c "UPDATE oauthclient SET preauthorized = true WHERE client_id = '${s.oauth-client-id}'"
1633 + serviceConfig.ExecStart = "${pkgs.sourcehut.metasrht}/bin/metasrht-api -b ${cfg.listenAddress}:${toString (cfg.meta.port + 100)}";
1635 + extraTimers.metasrht-daily.timerConfig = {
1636 + OnCalendar = ["daily"];
1637 + AccuracySec = "1h";
1639 + extraConfig = mkMerge [
1642 + { assertion = let s = cfg.settings."meta.sr.ht::billing"; in
1643 + s.enabled == "yes" -> (s.stripe-public-key != null && s.stripe-secret-key != null);
1644 + message = "If meta.sr.ht::billing is enabled, the keys must be defined.";
1647 + environment.systemPackages = optional cfg.meta.enable
1648 + (pkgs.writeShellScriptBin "metasrht-manageuser" ''
1650 + if test "$(${pkgs.coreutils}/bin/id -n -u)" != '${cfg.meta.user}'
1651 + then exec sudo -u '${cfg.meta.user}' "$0" "$@"
1653 + # In order to load config.ini
1654 + if cd /run/sourcehut/metasrht
1655 + then exec ${cfg.python}/bin/metasrht-manageuser "$@"
1657 + Please run: sudo systemctl start metasrht
1664 + (mkIf cfg.nginx.enable {
1665 + services.nginx.virtualHosts."meta.${domain}" = {
1666 + locations."/query" = {
1667 + proxyPass = cfg.settings."meta.sr.ht".api-origin;
1669 + if ($request_method = 'OPTIONS') {
1670 + add_header 'Access-Control-Allow-Origin' '*';
1671 + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
1672 + add_header 'Access-Control-Allow-Headers' 'User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
1673 + add_header 'Access-Control-Max-Age' 1728000;
1674 + add_header 'Content-Type' 'text/plain; charset=utf-8';
1675 + add_header 'Content-Length' 0;
1679 + add_header 'Access-Control-Allow-Origin' '*';
1680 + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
1681 + add_header 'Access-Control-Allow-Headers' 'User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
1682 + add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
1690 + (import ./service.nix "pages" {
1691 + inherit configIniOfService;
1694 + srvsrht = "pagessrht";
1695 + version = pkgs.sourcehut.${srvsrht}.version;
1696 + stateDir = "/var/lib/sourcehut/${srvsrht}";
1697 + iniKey = "pages.sr.ht";
1699 + preStart = mkBefore ''
1701 + # Use the /run/sourcehut/${srvsrht}/config.ini
1702 + # installed by a previous ExecStartPre= in baseService
1703 + cd /run/sourcehut/${srvsrht}
1705 + if test ! -e ${stateDir}/db; then
1706 + ${postgresql.package}/bin/psql '${cfg.settings.${iniKey}.connection-string}' -f ${pkgs.sourcehut.pagessrht}/share/sql/schema.sql
1707 + echo ${version} >${stateDir}/db
1710 + ${optionalString cfg.settings.${iniKey}.migrate-on-upgrade ''
1711 + # Just try all the migrations because they're not linked to the version
1712 + for sql in ${pkgs.sourcehut.pagessrht}/share/sql/migrations/*.sql; do
1713 + ${postgresql.package}/bin/psql '${cfg.settings.${iniKey}.connection-string}' -f "$sql" || true
1718 + touch ${stateDir}/webhook
1721 + ExecStart = mkForce "${pkgs.sourcehut.pagessrht}/bin/pages.sr.ht -b ${cfg.listenAddress}:${toString cfg.pages.port}";
1726 + (import ./service.nix "paste" {
1727 + inherit configIniOfService;
1731 + (import ./service.nix "todo" {
1732 + inherit configIniOfService;
1735 + extraServices.todosrht-lmtp = {
1736 + wants = [ "postfix.service" ];
1737 + unitConfig.JoinsNamespaceOf = optional cfg.postfix.enable "postfix.service";
1738 + serviceConfig.ExecStart = "${cfg.python}/bin/todosrht-lmtp";
1739 + # Avoid crashing: os.chown(sock, os.getuid(), sock_gid)
1740 + serviceConfig.PrivateUsers = mkForce false;
1742 + extraConfig = mkIf cfg.postfix.enable {
1743 + users.groups.${postfix.group}.members = [ cfg.todo.user ];
1744 + services.sourcehut.settings."todo.sr.ht::mail".sock-group = postfix.group;
1745 + services.postfix = {
1746 + destination = [ "todo.${domain}" ];
1747 + # FIXME: an accurate recipient list should be queried
1748 + # from the todo.sr.ht PostgreSQL database to avoid backscattering.
1749 + # But usernames are unfortunately not in that database but in meta.sr.ht.
1750 + # Note that two syntaxes are allowed:
1751 + # - ~username/tracker-name@todo.${domain}
1752 + # - u.username.tracker-name@todo.${domain}
1753 + localRecipients = [ "@todo.${domain}" ];
1755 + todo.${domain} lmtp:unix:${cfg.settings."todo.sr.ht::mail".sock}
1761 + (mkRenamedOptionModule [ "services" "sourcehut" "originBase" ]
1762 + [ "services" "sourcehut" "settings" "sr.ht" "global-domain" ])
1763 + (mkRenamedOptionModule [ "services" "sourcehut" "address" ]
1764 + [ "services" "sourcehut" "listenAddress" ])
1768 meta.doc = ./sourcehut.xml;
1769 - meta.maintainers = with maintainers; [ tomberek ];
1770 + meta.maintainers = with maintainers; [ julm tomberek ];
1772 diff --git a/nixos/modules/services/misc/sourcehut/dispatch.nix b/nixos/modules/services/misc/sourcehut/dispatch.nix
1773 deleted file mode 100644
1774 index a9db17bebe8..00000000000
1775 --- a/nixos/modules/services/misc/sourcehut/dispatch.nix
1778 -{ config, lib, pkgs, ... }:
1782 - cfg = config.services.sourcehut;
1783 - cfgIni = cfg.settings;
1784 - scfg = cfg.dispatch;
1785 - iniKey = "dispatch.sr.ht";
1787 - drv = pkgs.sourcehut.dispatchsrht;
1790 - options.services.sourcehut.dispatch = {
1793 - default = "dispatchsrht";
1795 - User for dispatch.sr.ht.
1800 - type = types.port;
1803 - Port on which the "dispatch" module should listen.
1807 - database = mkOption {
1809 - default = "dispatch.sr.ht";
1811 - PostgreSQL database name for dispatch.sr.ht.
1815 - statePath = mkOption {
1816 - type = types.path;
1817 - default = "${cfg.statePath}/dispatchsrht";
1819 - State path for dispatch.sr.ht.
1824 - config = with scfg; lib.mkIf (cfg.enable && elem "dispatch" cfg.services) {
1829 - isSystemUser = true;
1831 - description = "dispatch.sr.ht user";
1840 - services.postgresql = {
1841 - authentication = ''
1842 - local ${database} ${user} trust
1844 - ensureDatabases = [ database ];
1848 - ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
1854 - tmpfiles.rules = [
1855 - "d ${statePath} 0750 ${user} ${user} -"
1858 - services.dispatchsrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
1859 - after = [ "postgresql.service" "network.target" ];
1860 - requires = [ "postgresql.service" ];
1861 - wantedBy = [ "multi-user.target" ];
1863 - description = "dispatch.sr.ht website service";
1865 - serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
1869 - services.sourcehut.settings = {
1870 - # URL dispatch.sr.ht is being served at (protocol://domain)
1871 - "dispatch.sr.ht".origin = mkDefault "http://dispatch.${cfg.originBase}";
1872 - # Address and port to bind the debug server to
1873 - "dispatch.sr.ht".debug-host = mkDefault "0.0.0.0";
1874 - "dispatch.sr.ht".debug-port = mkDefault port;
1875 - # Configures the SQLAlchemy connection string for the database.
1876 - "dispatch.sr.ht".connection-string = mkDefault "postgresql:///${database}?user=${user}&host=/var/run/postgresql";
1877 - # Set to "yes" to automatically run migrations on package upgrade.
1878 - "dispatch.sr.ht".migrate-on-upgrade = mkDefault "yes";
1879 - # dispatch.sr.ht's OAuth client ID and secret for meta.sr.ht
1880 - # Register your client at meta.example.org/oauth
1881 - "dispatch.sr.ht".oauth-client-id = mkDefault null;
1882 - "dispatch.sr.ht".oauth-client-secret = mkDefault null;
1884 - # Github Integration
1885 - "dispatch.sr.ht::github".oauth-client-id = mkDefault null;
1886 - "dispatch.sr.ht::github".oauth-client-secret = mkDefault null;
1888 - # Gitlab Integration
1889 - "dispatch.sr.ht::gitlab".enabled = mkDefault null;
1890 - "dispatch.sr.ht::gitlab".canonical-upstream = mkDefault "gitlab.com";
1891 - "dispatch.sr.ht::gitlab".repo-cache = mkDefault "./repo-cache";
1892 - # "dispatch.sr.ht::gitlab"."gitlab.com" = mkDefault "GitLab:application id:secret";
1895 - services.nginx.virtualHosts."dispatch.${cfg.originBase}" = {
1897 - locations."/".proxyPass = "http://${cfg.address}:${toString port}";
1898 - locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
1899 - locations."/static".root = "${pkgs.sourcehut.dispatchsrht}/${pkgs.sourcehut.python.sitePackages}/dispatchsrht";
1903 diff --git a/nixos/modules/services/misc/sourcehut/git.nix b/nixos/modules/services/misc/sourcehut/git.nix
1904 deleted file mode 100644
1905 index 2653d77876d..00000000000
1906 --- a/nixos/modules/services/misc/sourcehut/git.nix
1909 -{ config, lib, pkgs, ... }:
1913 - cfg = config.services.sourcehut;
1915 - iniKey = "git.sr.ht";
1917 - rcfg = config.services.redis;
1918 - drv = pkgs.sourcehut.gitsrht;
1921 - options.services.sourcehut.git = {
1929 - User for git.sr.ht.
1934 - type = types.port;
1937 - Port on which the "git" module should listen.
1941 - database = mkOption {
1943 - default = "git.sr.ht";
1945 - PostgreSQL database name for git.sr.ht.
1949 - statePath = mkOption {
1950 - type = types.path;
1951 - default = "${cfg.statePath}/gitsrht";
1953 - State path for git.sr.ht.
1957 - package = mkOption {
1958 - type = types.package;
1959 - default = pkgs.git;
1960 - defaultText = literalExpression "pkgs.git";
1961 - example = literalExpression "pkgs.gitFull";
1963 - Git package for git.sr.ht. This can help silence collisions.
1968 - config = with scfg; lib.mkIf (cfg.enable && elem "git" cfg.services) {
1969 - # sshd refuses to run with `Unsafe AuthorizedKeysCommand ... bad ownership or modes for directory /nix/store`
1970 - environment.etc."ssh/gitsrht-dispatch" = {
1973 - #! ${pkgs.stdenv.shell}
1974 - ${cfg.python}/bin/gitsrht-dispatch "$@"
1978 - # Needs this in the $PATH when sshing into the server
1979 - environment.systemPackages = [ cfg.git.package ];
1984 - isSystemUser = true;
1986 - # https://stackoverflow.com/questions/22314298/git-push-results-in-fatal-protocol-error-bad-line-length-character-this
1987 - # Probably could use gitsrht-shell if output is restricted to just parameters...
1988 - shell = pkgs.bash;
1989 - description = "git.sr.ht user";
1999 - cron.systemCronJobs = [ "*/20 * * * * ${cfg.python}/bin/gitsrht-periodic" ];
2000 - fcgiwrap.enable = true;
2002 - openssh.authorizedKeysCommand = ''/etc/ssh/gitsrht-dispatch "%u" "%h" "%t" "%k"'';
2003 - openssh.authorizedKeysCommandUser = "root";
2004 - openssh.extraConfig = ''
2005 - PermitUserEnvironment SRHT_*
2009 - authentication = ''
2010 - local ${database} ${user} trust
2012 - ensureDatabases = [ database ];
2016 - ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
2023 - tmpfiles.rules = [
2024 - # /var/log is owned by root
2025 - "f /var/log/git-srht-shell 0644 ${user} ${user} -"
2027 - "d ${statePath} 0750 ${user} ${user} -"
2028 - "d ${cfg.settings."${iniKey}".repos} 2755 ${user} ${user} -"
2032 - gitsrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
2033 - after = [ "redis.service" "postgresql.service" "network.target" ];
2034 - requires = [ "redis.service" "postgresql.service" ];
2035 - wantedBy = [ "multi-user.target" ];
2037 - # Needs internally to create repos at the very least
2038 - path = [ pkgs.git ];
2039 - description = "git.sr.ht website service";
2041 - serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
2044 - gitsrht-webhooks = {
2045 - after = [ "postgresql.service" "network.target" ];
2046 - requires = [ "postgresql.service" ];
2047 - wantedBy = [ "multi-user.target" ];
2049 - description = "git.sr.ht webhooks service";
2053 - Restart = "always";
2056 - serviceConfig.ExecStart = "${cfg.python}/bin/celery -A ${drv.pname}.webhooks worker --loglevel=info";
2061 - services.sourcehut.settings = {
2062 - # URL git.sr.ht is being served at (protocol://domain)
2063 - "git.sr.ht".origin = mkDefault "http://git.${cfg.originBase}";
2064 - # Address and port to bind the debug server to
2065 - "git.sr.ht".debug-host = mkDefault "0.0.0.0";
2066 - "git.sr.ht".debug-port = mkDefault port;
2067 - # Configures the SQLAlchemy connection string for the database.
2068 - "git.sr.ht".connection-string = mkDefault "postgresql:///${database}?user=${user}&host=/var/run/postgresql";
2069 - # Set to "yes" to automatically run migrations on package upgrade.
2070 - "git.sr.ht".migrate-on-upgrade = mkDefault "yes";
2071 - # The redis connection used for the webhooks worker
2072 - "git.sr.ht".webhooks = mkDefault "redis://${rcfg.bind}:${toString rcfg.port}/1";
2074 - # A post-update script which is installed in every git repo.
2075 - "git.sr.ht".post-update-script = mkDefault "${pkgs.sourcehut.gitsrht}/bin/gitsrht-update-hook";
2077 - # git.sr.ht's OAuth client ID and secret for meta.sr.ht
2078 - # Register your client at meta.example.org/oauth
2079 - "git.sr.ht".oauth-client-id = mkDefault null;
2080 - "git.sr.ht".oauth-client-secret = mkDefault null;
2081 - # Path to git repositories on disk
2082 - "git.sr.ht".repos = mkDefault "/var/lib/git";
2084 - "git.sr.ht".outgoing-domain = mkDefault "http://git.${cfg.originBase}";
2086 - # The authorized keys hook uses this to dispatch to various handlers
2087 - # The format is a program to exec into as the key, and the user to match as the
2088 - # value. When someone tries to log in as this user, this program is executed
2089 - # and is expected to omit an AuthorizedKeys file.
2091 - # Discard of the string context is in order to allow derivation-derived strings.
2092 - # This is safe if the relevant package is installed which will be the case if the setting is utilized.
2093 - "git.sr.ht::dispatch".${builtins.unsafeDiscardStringContext "${pkgs.sourcehut.gitsrht}/bin/gitsrht-keys"} = mkDefault "${user}:${user}";
2096 - services.nginx.virtualHosts."git.${cfg.originBase}" = {
2098 - locations."/".proxyPass = "http://${cfg.address}:${toString port}";
2099 - locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
2100 - locations."/static".root = "${pkgs.sourcehut.gitsrht}/${pkgs.sourcehut.python.sitePackages}/gitsrht";
2102 - location = /authorize {
2103 - proxy_pass http://${cfg.address}:${toString port};
2104 - proxy_pass_request_body off;
2105 - proxy_set_header Content-Length "";
2106 - proxy_set_header X-Original-URI $request_uri;
2108 - location ~ ^/([^/]+)/([^/]+)/(HEAD|info/refs|objects/info/.*|git-upload-pack).*$ {
2109 - auth_request /authorize;
2110 - root /var/lib/git;
2111 - fastcgi_pass unix:/run/fcgiwrap.sock;
2112 - fastcgi_param SCRIPT_FILENAME ${pkgs.git}/bin/git-http-backend;
2113 - fastcgi_param PATH_INFO $uri;
2114 - fastcgi_param GIT_PROJECT_ROOT $document_root;
2115 - fastcgi_read_timeout 500s;
2116 - include ${pkgs.nginx}/conf/fastcgi_params;
2124 diff --git a/nixos/modules/services/misc/sourcehut/hg.nix b/nixos/modules/services/misc/sourcehut/hg.nix
2125 deleted file mode 100644
2126 index 5cd36bb0455..00000000000
2127 --- a/nixos/modules/services/misc/sourcehut/hg.nix
2130 -{ config, lib, pkgs, ... }:
2134 - cfg = config.services.sourcehut;
2136 - iniKey = "hg.sr.ht";
2138 - rcfg = config.services.redis;
2139 - drv = pkgs.sourcehut.hgsrht;
2142 - options.services.sourcehut.hg = {
2149 - User for hg.sr.ht.
2154 - type = types.port;
2157 - Port on which the "hg" module should listen.
2161 - database = mkOption {
2163 - default = "hg.sr.ht";
2165 - PostgreSQL database name for hg.sr.ht.
2169 - statePath = mkOption {
2170 - type = types.path;
2171 - default = "${cfg.statePath}/hgsrht";
2173 - State path for hg.sr.ht.
2177 - cloneBundles = mkOption {
2178 - type = types.bool;
2181 - Generate clonebundles (which require more disk space but dramatically speed up cloning large repositories).
2186 - config = with scfg; lib.mkIf (cfg.enable && elem "hg" cfg.services) {
2187 - # In case it ever comes into being
2188 - environment.etc."ssh/hgsrht-dispatch" = {
2191 - #! ${pkgs.stdenv.shell}
2192 - ${cfg.python}/bin/gitsrht-dispatch $@
2196 - environment.systemPackages = [ pkgs.mercurial ];
2201 - isSystemUser = true;
2203 - # Assuming hg.sr.ht needs this too
2204 - shell = pkgs.bash;
2205 - description = "hg.sr.ht user";
2215 - cron.systemCronJobs = [ "*/20 * * * * ${cfg.python}/bin/hgsrht-periodic" ]
2216 - ++ optional cloneBundles "0 * * * * ${cfg.python}/bin/hgsrht-clonebundles";
2218 - openssh.authorizedKeysCommand = ''/etc/ssh/hgsrht-dispatch "%u" "%h" "%t" "%k"'';
2219 - openssh.authorizedKeysCommandUser = "root";
2220 - openssh.extraConfig = ''
2221 - PermitUserEnvironment SRHT_*
2225 - authentication = ''
2226 - local ${database} ${user} trust
2228 - ensureDatabases = [ database ];
2232 - ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
2239 - tmpfiles.rules = [
2240 - # /var/log is owned by root
2241 - "f /var/log/hg-srht-shell 0644 ${user} ${user} -"
2243 - "d ${statePath} 0750 ${user} ${user} -"
2244 - "d ${cfg.settings."${iniKey}".repos} 2755 ${user} ${user} -"
2247 - services.hgsrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
2248 - after = [ "redis.service" "postgresql.service" "network.target" ];
2249 - requires = [ "redis.service" "postgresql.service" ];
2250 - wantedBy = [ "multi-user.target" ];
2252 - path = [ pkgs.mercurial ];
2253 - description = "hg.sr.ht website service";
2255 - serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
2259 - services.sourcehut.settings = {
2260 - # URL hg.sr.ht is being served at (protocol://domain)
2261 - "hg.sr.ht".origin = mkDefault "http://hg.${cfg.originBase}";
2262 - # Address and port to bind the debug server to
2263 - "hg.sr.ht".debug-host = mkDefault "0.0.0.0";
2264 - "hg.sr.ht".debug-port = mkDefault port;
2265 - # Configures the SQLAlchemy connection string for the database.
2266 - "hg.sr.ht".connection-string = mkDefault "postgresql:///${database}?user=${user}&host=/var/run/postgresql";
2267 - # The redis connection used for the webhooks worker
2268 - "hg.sr.ht".webhooks = mkDefault "redis://${rcfg.bind}:${toString rcfg.port}/1";
2269 - # A post-update script which is installed in every mercurial repo.
2270 - "hg.sr.ht".changegroup-script = mkDefault "${cfg.python}/bin/hgsrht-hook-changegroup";
2271 - # hg.sr.ht's OAuth client ID and secret for meta.sr.ht
2272 - # Register your client at meta.example.org/oauth
2273 - "hg.sr.ht".oauth-client-id = mkDefault null;
2274 - "hg.sr.ht".oauth-client-secret = mkDefault null;
2275 - # Path to mercurial repositories on disk
2276 - "hg.sr.ht".repos = mkDefault "/var/lib/hg";
2277 - # Path to the srht mercurial extension
2278 - # (defaults to where the hgsrht code is)
2279 - # "hg.sr.ht".srhtext = mkDefault null;
2280 - # .hg/store size (in MB) past which the nightly job generates clone bundles.
2281 - # "hg.sr.ht".clone_bundle_threshold = mkDefault 50;
2282 - # Path to hg-ssh (if not in $PATH)
2283 - # "hg.sr.ht".hg_ssh = mkDefault /path/to/hg-ssh;
2285 - # The authorized keys hook uses this to dispatch to various handlers
2286 - # The format is a program to exec into as the key, and the user to match as the
2287 - # value. When someone tries to log in as this user, this program is executed
2288 - # and is expected to omit an AuthorizedKeys file.
2290 - # Uncomment the relevant lines to enable the various sr.ht dispatchers.
2291 - "hg.sr.ht::dispatch"."/run/current-system/sw/bin/hgsrht-keys" = mkDefault "${user}:${user}";
2294 - # TODO: requires testing and addition of hg-specific requirements
2295 - services.nginx.virtualHosts."hg.${cfg.originBase}" = {
2297 - locations."/".proxyPass = "http://${cfg.address}:${toString port}";
2298 - locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
2299 - locations."/static".root = "${pkgs.sourcehut.hgsrht}/${pkgs.sourcehut.python.sitePackages}/hgsrht";
2303 diff --git a/nixos/modules/services/misc/sourcehut/hub.nix b/nixos/modules/services/misc/sourcehut/hub.nix
2304 deleted file mode 100644
2305 index be3ea21011c..00000000000
2306 --- a/nixos/modules/services/misc/sourcehut/hub.nix
2309 -{ config, lib, pkgs, ... }:
2313 - cfg = config.services.sourcehut;
2314 - cfgIni = cfg.settings;
2316 - iniKey = "hub.sr.ht";
2318 - drv = pkgs.sourcehut.hubsrht;
2321 - options.services.sourcehut.hub = {
2324 - default = "hubsrht";
2326 - User for hub.sr.ht.
2331 - type = types.port;
2334 - Port on which the "hub" module should listen.
2338 - database = mkOption {
2340 - default = "hub.sr.ht";
2342 - PostgreSQL database name for hub.sr.ht.
2346 - statePath = mkOption {
2347 - type = types.path;
2348 - default = "${cfg.statePath}/hubsrht";
2350 - State path for hub.sr.ht.
2355 - config = with scfg; lib.mkIf (cfg.enable && elem "hub" cfg.services) {
2359 - isSystemUser = true;
2361 - description = "hub.sr.ht user";
2370 - services.postgresql = {
2371 - authentication = ''
2372 - local ${database} ${user} trust
2374 - ensureDatabases = [ database ];
2378 - ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
2384 - tmpfiles.rules = [
2385 - "d ${statePath} 0750 ${user} ${user} -"
2388 - services.hubsrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
2389 - after = [ "postgresql.service" "network.target" ];
2390 - requires = [ "postgresql.service" ];
2391 - wantedBy = [ "multi-user.target" ];
2393 - description = "hub.sr.ht website service";
2395 - serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
2399 - services.sourcehut.settings = {
2400 - # URL hub.sr.ht is being served at (protocol://domain)
2401 - "hub.sr.ht".origin = mkDefault "http://hub.${cfg.originBase}";
2402 - # Address and port to bind the debug server to
2403 - "hub.sr.ht".debug-host = mkDefault "0.0.0.0";
2404 - "hub.sr.ht".debug-port = mkDefault port;
2405 - # Configures the SQLAlchemy connection string for the database.
2406 - "hub.sr.ht".connection-string = mkDefault "postgresql:///${database}?user=${user}&host=/var/run/postgresql";
2407 - # Set to "yes" to automatically run migrations on package upgrade.
2408 - "hub.sr.ht".migrate-on-upgrade = mkDefault "yes";
2409 - # hub.sr.ht's OAuth client ID and secret for meta.sr.ht
2410 - # Register your client at meta.example.org/oauth
2411 - "hub.sr.ht".oauth-client-id = mkDefault null;
2412 - "hub.sr.ht".oauth-client-secret = mkDefault null;
2415 - services.nginx.virtualHosts."${cfg.originBase}" = {
2417 - locations."/".proxyPass = "http://${cfg.address}:${toString port}";
2418 - locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
2419 - locations."/static".root = "${pkgs.sourcehut.hubsrht}/${pkgs.sourcehut.python.sitePackages}/hubsrht";
2421 - services.nginx.virtualHosts."hub.${cfg.originBase}" = {
2422 - globalRedirect = "${cfg.originBase}";
2427 diff --git a/nixos/modules/services/misc/sourcehut/lists.nix b/nixos/modules/services/misc/sourcehut/lists.nix
2428 deleted file mode 100644
2429 index 7b1fe9fd463..00000000000
2430 --- a/nixos/modules/services/misc/sourcehut/lists.nix
2433 -# Email setup is fairly involved, useful references:
2434 -# https://drewdevault.com/2018/08/05/Local-mail-server.html
2436 -{ config, lib, pkgs, ... }:
2440 - cfg = config.services.sourcehut;
2441 - cfgIni = cfg.settings;
2443 - iniKey = "lists.sr.ht";
2445 - rcfg = config.services.redis;
2446 - drv = pkgs.sourcehut.listssrht;
2449 - options.services.sourcehut.lists = {
2452 - default = "listssrht";
2454 - User for lists.sr.ht.
2459 - type = types.port;
2462 - Port on which the "lists" module should listen.
2466 - database = mkOption {
2468 - default = "lists.sr.ht";
2470 - PostgreSQL database name for lists.sr.ht.
2474 - statePath = mkOption {
2475 - type = types.path;
2476 - default = "${cfg.statePath}/listssrht";
2478 - State path for lists.sr.ht.
2483 - config = with scfg; lib.mkIf (cfg.enable && elem "lists" cfg.services) {
2487 - isSystemUser = true;
2489 - extraGroups = [ "postfix" ];
2490 - description = "lists.sr.ht user";
2498 - services.postgresql = {
2499 - authentication = ''
2500 - local ${database} ${user} trust
2502 - ensureDatabases = [ database ];
2506 - ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
2512 - tmpfiles.rules = [
2513 - "d ${statePath} 0750 ${user} ${user} -"
2517 - listssrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
2518 - after = [ "postgresql.service" "network.target" ];
2519 - requires = [ "postgresql.service" ];
2520 - wantedBy = [ "multi-user.target" ];
2522 - description = "lists.sr.ht website service";
2524 - serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
2527 - listssrht-process = {
2528 - after = [ "postgresql.service" "network.target" ];
2529 - requires = [ "postgresql.service" ];
2530 - wantedBy = [ "multi-user.target" ];
2532 - description = "lists.sr.ht process service";
2536 - Restart = "always";
2537 - ExecStart = "${cfg.python}/bin/celery -A ${drv.pname}.process worker --loglevel=info";
2541 - listssrht-lmtp = {
2542 - after = [ "postgresql.service" "network.target" ];
2543 - requires = [ "postgresql.service" ];
2544 - wantedBy = [ "multi-user.target" ];
2546 - description = "lists.sr.ht process service";
2550 - Restart = "always";
2551 - ExecStart = "${cfg.python}/bin/listssrht-lmtp";
2556 - listssrht-webhooks = {
2557 - after = [ "postgresql.service" "network.target" ];
2558 - requires = [ "postgresql.service" ];
2559 - wantedBy = [ "multi-user.target" ];
2561 - description = "lists.sr.ht webhooks service";
2565 - Restart = "always";
2566 - ExecStart = "${cfg.python}/bin/celery -A ${drv.pname}.webhooks worker --loglevel=info";
2572 - services.sourcehut.settings = {
2573 - # URL lists.sr.ht is being served at (protocol://domain)
2574 - "lists.sr.ht".origin = mkDefault "http://lists.${cfg.originBase}";
2575 - # Address and port to bind the debug server to
2576 - "lists.sr.ht".debug-host = mkDefault "0.0.0.0";
2577 - "lists.sr.ht".debug-port = mkDefault port;
2578 - # Configures the SQLAlchemy connection string for the database.
2579 - "lists.sr.ht".connection-string = mkDefault "postgresql:///${database}?user=${user}&host=/var/run/postgresql";
2580 - # Set to "yes" to automatically run migrations on package upgrade.
2581 - "lists.sr.ht".migrate-on-upgrade = mkDefault "yes";
2582 - # lists.sr.ht's OAuth client ID and secret for meta.sr.ht
2583 - # Register your client at meta.example.org/oauth
2584 - "lists.sr.ht".oauth-client-id = mkDefault null;
2585 - "lists.sr.ht".oauth-client-secret = mkDefault null;
2586 - # Outgoing email for notifications generated by users
2587 - "lists.sr.ht".notify-from = mkDefault "CHANGEME@example.org";
2588 - # The redis connection used for the webhooks worker
2589 - "lists.sr.ht".webhooks = mkDefault "redis://${rcfg.bind}:${toString rcfg.port}/2";
2590 - # The redis connection used for the celery worker
2591 - "lists.sr.ht".redis = mkDefault "redis://${rcfg.bind}:${toString rcfg.port}/4";
2593 - "lists.sr.ht".network-key = mkDefault null;
2595 - "lists.sr.ht".allow-new-lists = mkDefault "no";
2597 - "lists.sr.ht".posting-domain = mkDefault "lists.${cfg.originBase}";
2599 - # Path for the lmtp daemon's unix socket. Direct incoming mail to this socket.
2600 - # Alternatively, specify IP:PORT and an SMTP server will be run instead.
2601 - "lists.sr.ht::worker".sock = mkDefault "/tmp/lists.sr.ht-lmtp.sock";
2602 - # The lmtp daemon will make the unix socket group-read/write for users in this
2604 - "lists.sr.ht::worker".sock-group = mkDefault "postfix";
2605 - "lists.sr.ht::worker".reject-url = mkDefault "https://man.sr.ht/lists.sr.ht/etiquette.md";
2606 - "lists.sr.ht::worker".reject-mimetypes = mkDefault "text/html";
2610 - services.nginx.virtualHosts."lists.${cfg.originBase}" = {
2612 - locations."/".proxyPass = "http://${cfg.address}:${toString port}";
2613 - locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
2614 - locations."/static".root = "${pkgs.sourcehut.listssrht}/${pkgs.sourcehut.python.sitePackages}/listssrht";
2618 diff --git a/nixos/modules/services/misc/sourcehut/man.nix b/nixos/modules/services/misc/sourcehut/man.nix
2619 deleted file mode 100644
2620 index 7693396d187..00000000000
2621 --- a/nixos/modules/services/misc/sourcehut/man.nix
2624 -{ config, lib, pkgs, ... }:
2628 - cfg = config.services.sourcehut;
2629 - cfgIni = cfg.settings;
2631 - iniKey = "man.sr.ht";
2633 - drv = pkgs.sourcehut.mansrht;
2636 - options.services.sourcehut.man = {
2639 - default = "mansrht";
2641 - User for man.sr.ht.
2646 - type = types.port;
2649 - Port on which the "man" module should listen.
2653 - database = mkOption {
2655 - default = "man.sr.ht";
2657 - PostgreSQL database name for man.sr.ht.
2661 - statePath = mkOption {
2662 - type = types.path;
2663 - default = "${cfg.statePath}/mansrht";
2665 - State path for man.sr.ht.
2670 - config = with scfg; lib.mkIf (cfg.enable && elem "man" cfg.services) {
2674 - assertion = hasAttrByPath [ "git.sr.ht" "oauth-client-id" ] cfgIni;
2675 - message = "man.sr.ht needs access to git.sr.ht.";
2682 - isSystemUser = true;
2684 - description = "man.sr.ht user";
2693 - services.postgresql = {
2694 - authentication = ''
2695 - local ${database} ${user} trust
2697 - ensureDatabases = [ database ];
2701 - ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
2707 - tmpfiles.rules = [
2708 - "d ${statePath} 0750 ${user} ${user} -"
2711 - services.mansrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
2712 - after = [ "postgresql.service" "network.target" ];
2713 - requires = [ "postgresql.service" ];
2714 - wantedBy = [ "multi-user.target" ];
2716 - description = "man.sr.ht website service";
2718 - serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
2722 - services.sourcehut.settings = {
2723 - # URL man.sr.ht is being served at (protocol://domain)
2724 - "man.sr.ht".origin = mkDefault "http://man.${cfg.originBase}";
2725 - # Address and port to bind the debug server to
2726 - "man.sr.ht".debug-host = mkDefault "0.0.0.0";
2727 - "man.sr.ht".debug-port = mkDefault port;
2728 - # Configures the SQLAlchemy connection string for the database.
2729 - "man.sr.ht".connection-string = mkDefault "postgresql:///${database}?user=${user}&host=/var/run/postgresql";
2730 - # Set to "yes" to automatically run migrations on package upgrade.
2731 - "man.sr.ht".migrate-on-upgrade = mkDefault "yes";
2732 - # man.sr.ht's OAuth client ID and secret for meta.sr.ht
2733 - # Register your client at meta.example.org/oauth
2734 - "man.sr.ht".oauth-client-id = mkDefault null;
2735 - "man.sr.ht".oauth-client-secret = mkDefault null;
2738 - services.nginx.virtualHosts."man.${cfg.originBase}" = {
2740 - locations."/".proxyPass = "http://${cfg.address}:${toString port}";
2741 - locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
2742 - locations."/static".root = "${pkgs.sourcehut.mansrht}/${pkgs.sourcehut.python.sitePackages}/mansrht";
2746 diff --git a/nixos/modules/services/misc/sourcehut/meta.nix b/nixos/modules/services/misc/sourcehut/meta.nix
2747 deleted file mode 100644
2748 index 56127a824eb..00000000000
2749 --- a/nixos/modules/services/misc/sourcehut/meta.nix
2752 -{ config, lib, pkgs, ... }:
2756 - cfg = config.services.sourcehut;
2757 - cfgIni = cfg.settings;
2759 - iniKey = "meta.sr.ht";
2761 - rcfg = config.services.redis;
2762 - drv = pkgs.sourcehut.metasrht;
2765 - options.services.sourcehut.meta = {
2768 - default = "metasrht";
2770 - User for meta.sr.ht.
2775 - type = types.port;
2778 - Port on which the "meta" module should listen.
2782 - database = mkOption {
2784 - default = "meta.sr.ht";
2786 - PostgreSQL database name for meta.sr.ht.
2790 - statePath = mkOption {
2791 - type = types.path;
2792 - default = "${cfg.statePath}/metasrht";
2794 - State path for meta.sr.ht.
2799 - config = with scfg; lib.mkIf (cfg.enable && elem "meta" cfg.services) {
2803 - assertion = with cfgIni."meta.sr.ht::billing"; enabled == "yes" -> (stripe-public-key != null && stripe-secret-key != null);
2804 - message = "If meta.sr.ht::billing is enabled, the keys should be defined.";
2811 - isSystemUser = true;
2813 - description = "meta.sr.ht user";
2822 - services.cron.systemCronJobs = [ "0 0 * * * ${cfg.python}/bin/metasrht-daily" ];
2823 - services.postgresql = {
2824 - authentication = ''
2825 - local ${database} ${user} trust
2827 - ensureDatabases = [ database ];
2831 - ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
2837 - tmpfiles.rules = [
2838 - "d ${statePath} 0750 ${user} ${user} -"
2842 - metasrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
2843 - after = [ "postgresql.service" "network.target" ];
2844 - requires = [ "postgresql.service" ];
2845 - wantedBy = [ "multi-user.target" ];
2847 - description = "meta.sr.ht website service";
2850 - # Configure client(s) as "preauthorized"
2851 - ${concatMapStringsSep "\n\n"
2853 - if ! test -e "${statePath}/${attr}.oauth" || [ "$(cat ${statePath}/${attr}.oauth)" != "${cfgIni."${attr}".oauth-client-id}" ]; then
2854 - # Configure ${attr}'s OAuth client as "preauthorized"
2855 - psql ${database} \
2856 - -c "UPDATE oauthclient SET preauthorized = true WHERE client_id = '${cfgIni."${attr}".oauth-client-id}'"
2858 - printf "%s" "${cfgIni."${attr}".oauth-client-id}" > "${statePath}/${attr}.oauth"
2861 - (builtins.attrNames (filterAttrs
2862 - (k: v: !(hasInfix "::" k) && builtins.hasAttr "oauth-client-id" v && v.oauth-client-id != null)
2866 - serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
2869 - metasrht-api = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
2870 - after = [ "postgresql.service" "network.target" ];
2871 - requires = [ "postgresql.service" ];
2872 - wantedBy = [ "multi-user.target" ];
2874 - description = "meta.sr.ht api service";
2877 - # Configure client(s) as "preauthorized"
2878 - ${concatMapStringsSep "\n\n"
2880 - if ! test -e "${statePath}/${attr}.oauth" || [ "$(cat ${statePath}/${attr}.oauth)" != "${cfgIni."${attr}".oauth-client-id}" ]; then
2881 - # Configure ${attr}'s OAuth client as "preauthorized"
2882 - psql ${database} \
2883 - -c "UPDATE oauthclient SET preauthorized = true WHERE client_id = '${cfgIni."${attr}".oauth-client-id}'"
2885 - printf "%s" "${cfgIni."${attr}".oauth-client-id}" > "${statePath}/${attr}.oauth"
2888 - (builtins.attrNames (filterAttrs
2889 - (k: v: !(hasInfix "::" k) && builtins.hasAttr "oauth-client-id" v && v.oauth-client-id != null)
2893 - serviceConfig.ExecStart = "${pkgs.sourcehut.metasrht}/bin/metasrht-api -b :${toString (port + 100)}";
2896 - metasrht-webhooks = {
2897 - after = [ "postgresql.service" "network.target" ];
2898 - requires = [ "postgresql.service" ];
2899 - wantedBy = [ "multi-user.target" ];
2901 - description = "meta.sr.ht webhooks service";
2905 - Restart = "always";
2906 - ExecStart = "${cfg.python}/bin/celery -A ${drv.pname}.webhooks worker --loglevel=info";
2913 - services.sourcehut.settings = {
2914 - # URL meta.sr.ht is being served at (protocol://domain)
2915 - "meta.sr.ht".origin = mkDefault "https://meta.${cfg.originBase}";
2916 - # Address and port to bind the debug server to
2917 - "meta.sr.ht".debug-host = mkDefault "0.0.0.0";
2918 - "meta.sr.ht".debug-port = mkDefault port;
2919 - # Configures the SQLAlchemy connection string for the database.
2920 - "meta.sr.ht".connection-string = mkDefault "postgresql:///${database}?user=${user}&host=/var/run/postgresql";
2921 - # Set to "yes" to automatically run migrations on package upgrade.
2922 - "meta.sr.ht".migrate-on-upgrade = mkDefault "yes";
2923 - # If "yes", the user will be sent the stock sourcehut welcome emails after
2924 - # signup (requires cron to be configured properly). These are specific to the
2925 - # sr.ht instance so you probably want to patch these before enabling this.
2926 - "meta.sr.ht".welcome-emails = mkDefault "no";
2928 - # The redis connection used for the webhooks worker
2929 - "meta.sr.ht".webhooks = mkDefault "redis://${rcfg.bind}:${toString rcfg.port}/6";
2931 - # If "no", public registration will not be permitted.
2932 - "meta.sr.ht::settings".registration = mkDefault "no";
2933 - # Where to redirect new users upon registration
2934 - "meta.sr.ht::settings".onboarding-redirect = mkDefault "https://meta.${cfg.originBase}";
2935 - # How many invites each user is issued upon registration (only applicable if
2936 - # open registration is disabled)
2937 - "meta.sr.ht::settings".user-invites = mkDefault 5;
2939 - # Origin URL for API, 100 more than web
2940 - "meta.sr.ht".api-origin = mkDefault "http://localhost:5100";
2942 - # You can add aliases for the client IDs of commonly used OAuth clients here.
2945 - "meta.sr.ht::aliases" = mkDefault { };
2946 - # "meta.sr.ht::aliases"."git.sr.ht" = 12345;
2948 - # "yes" to enable the billing system
2949 - "meta.sr.ht::billing".enabled = mkDefault "no";
2950 - # Get your keys at https://dashboard.stripe.com/account/apikeys
2951 - "meta.sr.ht::billing".stripe-public-key = mkDefault null;
2952 - "meta.sr.ht::billing".stripe-secret-key = mkDefault null;
2955 - services.nginx.virtualHosts."meta.${cfg.originBase}" = {
2957 - locations."/".proxyPass = "http://${cfg.address}:${toString port}";
2958 - locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
2959 - locations."/static".root = "${pkgs.sourcehut.metasrht}/${pkgs.sourcehut.python.sitePackages}/metasrht";
2963 diff --git a/nixos/modules/services/misc/sourcehut/paste.nix b/nixos/modules/services/misc/sourcehut/paste.nix
2964 deleted file mode 100644
2965 index b2d5151969e..00000000000
2966 --- a/nixos/modules/services/misc/sourcehut/paste.nix
2969 -{ config, lib, pkgs, ... }:
2973 - cfg = config.services.sourcehut;
2974 - cfgIni = cfg.settings;
2976 - iniKey = "paste.sr.ht";
2978 - rcfg = config.services.redis;
2979 - drv = pkgs.sourcehut.pastesrht;
2982 - options.services.sourcehut.paste = {
2985 - default = "pastesrht";
2987 - User for paste.sr.ht.
2992 - type = types.port;
2995 - Port on which the "paste" module should listen.
2999 - database = mkOption {
3001 - default = "paste.sr.ht";
3003 - PostgreSQL database name for paste.sr.ht.
3007 - statePath = mkOption {
3008 - type = types.path;
3009 - default = "${cfg.statePath}/pastesrht";
3011 - State path for pastesrht.sr.ht.
3016 - config = with scfg; lib.mkIf (cfg.enable && elem "paste" cfg.services) {
3020 - isSystemUser = true;
3022 - description = "paste.sr.ht user";
3031 - services.postgresql = {
3032 - authentication = ''
3033 - local ${database} ${user} trust
3035 - ensureDatabases = [ database ];
3039 - ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
3045 - tmpfiles.rules = [
3046 - "d ${statePath} 0750 ${user} ${user} -"
3050 - pastesrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
3051 - after = [ "postgresql.service" "network.target" ];
3052 - requires = [ "postgresql.service" ];
3053 - wantedBy = [ "multi-user.target" ];
3055 - description = "paste.sr.ht website service";
3057 - serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
3060 - pastesrht-webhooks = {
3061 - after = [ "postgresql.service" "network.target" ];
3062 - requires = [ "postgresql.service" ];
3063 - wantedBy = [ "multi-user.target" ];
3065 - description = "paste.sr.ht webhooks service";
3069 - Restart = "always";
3070 - ExecStart = "${cfg.python}/bin/celery -A ${drv.pname}.webhooks worker --loglevel=info";
3077 - services.sourcehut.settings = {
3078 - # URL paste.sr.ht is being served at (protocol://domain)
3079 - "paste.sr.ht".origin = mkDefault "http://paste.${cfg.originBase}";
3080 - # Address and port to bind the debug server to
3081 - "paste.sr.ht".debug-host = mkDefault "0.0.0.0";
3082 - "paste.sr.ht".debug-port = mkDefault port;
3083 - # Configures the SQLAlchemy connection string for the database.
3084 - "paste.sr.ht".connection-string = mkDefault "postgresql:///${database}?user=${user}&host=/var/run/postgresql";
3085 - # Set to "yes" to automatically run migrations on package upgrade.
3086 - "paste.sr.ht".migrate-on-upgrade = mkDefault "yes";
3087 - # paste.sr.ht's OAuth client ID and secret for meta.sr.ht
3088 - # Register your client at meta.example.org/oauth
3089 - "paste.sr.ht".oauth-client-id = mkDefault null;
3090 - "paste.sr.ht".oauth-client-secret = mkDefault null;
3091 - "paste.sr.ht".webhooks = mkDefault "redis://${rcfg.bind}:${toString rcfg.port}/5";
3094 - services.nginx.virtualHosts."paste.${cfg.originBase}" = {
3096 - locations."/".proxyPass = "http://${cfg.address}:${toString port}";
3097 - locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
3098 - locations."/static".root = "${pkgs.sourcehut.pastesrht}/${pkgs.sourcehut.python.sitePackages}/pastesrht";
3102 diff --git a/nixos/modules/services/misc/sourcehut/service.nix b/nixos/modules/services/misc/sourcehut/service.nix
3103 index 65b4ad020f9..f1706ad0a6a 100644
3104 --- a/nixos/modules/services/misc/sourcehut/service.nix
3105 +++ b/nixos/modules/services/misc/sourcehut/service.nix
3107 -{ config, pkgs, lib }:
3108 -serviceCfg: serviceDrv: iniKey: attrs:
3110 +{ configIniOfService
3111 +, srvsrht ? "${srv}srht" # Because "buildsrht" does not follow that pattern (missing an "s").
3112 +, iniKey ? "${srv}.sr.ht"
3116 +, extraServices ? {}
3120 +{ config, lib, pkgs, ... }:
3124 + inherit (config.services) postgresql;
3125 + redis = config.services.redis.servers."sourcehut-${srvsrht}";
3126 + inherit (config.users) users;
3127 cfg = config.services.sourcehut;
3128 - cfgIni = cfg.settings."${iniKey}";
3129 - pgSuperUser = config.services.postgresql.superUser;
3131 - setupDB = pkgs.writeScript "${serviceDrv.pname}-gen-db" ''
3132 - #! ${cfg.python}/bin/python
3133 - from ${serviceDrv.pname}.app import db
3136 + configIni = configIniOfService srv;
3137 + srvCfg = cfg.${srv};
3138 + baseService = serviceName: { allowStripe ? false }: extraService: let
3139 + runDir = "/run/sourcehut/${serviceName}";
3140 + rootDir = "/run/sourcehut/chroots/${serviceName}";
3142 + mkMerge [ extraService {
3143 + after = [ "network.target" ] ++
3144 + optional cfg.postgresql.enable "postgresql.service" ++
3145 + optional cfg.redis.enable "redis-sourcehut-${srvsrht}.service";
3147 + optional cfg.postgresql.enable "postgresql.service" ++
3148 + optional cfg.redis.enable "redis-sourcehut-${srvsrht}.service";
3149 + path = [ pkgs.gawk ];
3150 + environment.HOME = runDir;
3152 + User = mkDefault srvCfg.user;
3153 + Group = mkDefault srvCfg.group;
3154 + RuntimeDirectory = [
3155 + "sourcehut/${serviceName}"
3156 + # Used by *srht-keys which reads ../config.ini
3157 + "sourcehut/${serviceName}/subdir"
3158 + "sourcehut/chroots/${serviceName}"
3160 + RuntimeDirectoryMode = "2750";
3161 + # No need for the chroot path once inside the chroot
3162 + InaccessiblePaths = [ "-+${rootDir}" ];
3163 + # g+rx is for group members (eg. fcgiwrap or nginx)
3164 + # to read Git/Mercurial repositories, buildlogs, etc.
3165 + # o+x is for intermediate directories created by BindPaths= and like,
3166 + # as they're owned by root:root.
3168 + RootDirectory = rootDir;
3169 + RootDirectoryStartOnly = true;
3170 + PrivateTmp = true;
3171 + MountAPIVFS = true;
3172 + # config.ini is looked up in there, before /etc/srht/config.ini
3173 + # Note that it fails to be set in ExecStartPre=
3174 + WorkingDirectory = mkDefault ("-"+runDir);
3175 + BindReadOnlyPaths = [
3178 + "/run/booted-system"
3179 + "/run/current-system"
3182 + optional cfg.postgresql.enable "/run/postgresql" ++
3183 + optional cfg.redis.enable "/run/redis-sourcehut-${srvsrht}";
3184 + # LoadCredential= are unfortunately not available in ExecStartPre=
3185 + # Hence this one is run as root (the +) with RootDirectoryStartOnly=
3186 + # to reach credentials wherever they are.
3187 + # Note that each systemd service gets its own ${runDir}/config.ini file.
3188 + ExecStartPre = mkBefore [("+"+pkgs.writeShellScript "${serviceName}-credentials" ''
3190 + # Replace values begining with a '<' by the content of the file whose name is after.
3191 + gawk '{ if (match($0,/^([^=]+=)<(.+)/,m)) { getline f < m[2]; print m[1] f } else print $0 }' ${configIni} |
3192 + ${optionalString (!allowStripe) "gawk '!/^stripe-secret-key=/' |"}
3193 + install -o ${srvCfg.user} -g root -m 400 /dev/stdin ${runDir}/config.ini
3195 + # The following options are only for optimizing:
3196 + # systemd-analyze security
3197 + AmbientCapabilities = "";
3198 + CapabilityBoundingSet = "";
3199 + # ProtectClock= adds DeviceAllow=char-rtc r
3201 + LockPersonality = true;
3202 + MemoryDenyWriteExecute = true;
3203 + NoNewPrivileges = true;
3204 + PrivateDevices = true;
3205 + PrivateMounts = true;
3206 + PrivateNetwork = mkDefault false;
3207 + PrivateUsers = true;
3208 + ProcSubset = "pid";
3209 + ProtectClock = true;
3210 + ProtectControlGroups = true;
3211 + ProtectHome = true;
3212 + ProtectHostname = true;
3213 + ProtectKernelLogs = true;
3214 + ProtectKernelModules = true;
3215 + ProtectKernelTunables = true;
3216 + ProtectProc = "invisible";
3217 + ProtectSystem = "strict";
3219 + RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ];
3220 + RestrictNamespaces = true;
3221 + RestrictRealtime = true;
3222 + RestrictSUIDSGID = true;
3223 + #SocketBindAllow = [ "tcp:${toString srvCfg.port}" "tcp:${toString srvCfg.prometheusPort}" ];
3224 + #SocketBindDeny = "any";
3225 + SystemCallFilter = [
3227 + "~@aio" "~@keyring" "~@memlock" "~@privileged" "~@resources" "~@timer"
3228 + "@chown" "@setuid"
3230 + SystemCallArchitectures = "native";
3234 -with serviceCfg; with lib; recursiveUpdate
3236 - environment.HOME = statePath;
3237 - path = [ config.services.postgresql.package ] ++ (attrs.path or [ ]);
3238 - restartTriggers = [ config.environment.etc."sr.ht/config.ini".source ];
3243 - Restart = "always";
3244 - WorkingDirectory = statePath;
3245 - } // (if (cfg.statePath == "/var/lib/sourcehut/${serviceDrv.pname}") then {
3246 - StateDirectory = [ "sourcehut/${serviceDrv.pname}" ];
3249 + options.services.sourcehut.${srv} = {
3250 + enable = mkEnableOption "${srv} service";
3253 - if ! test -e ${statePath}/db; then
3254 - # Setup the initial database
3258 + default = srvsrht;
3260 + User for ${srv}.sr.ht.
3264 - # Set the initial state of the database for future database upgrades
3265 - if test -e ${cfg.python}/bin/${serviceDrv.pname}-migrate; then
3266 - # Run alembic stamp head once to tell alembic the schema is up-to-date
3267 - ${cfg.python}/bin/${serviceDrv.pname}-migrate stamp head
3269 + group = mkOption {
3271 + default = srvsrht;
3273 + Group for ${srv}.sr.ht.
3274 + Membership grants access to the Git/Mercurial repositories by default,
3275 + but not to the config.ini file (where secrets are).
3279 - printf "%s" "${serviceDrv.version}" > ${statePath}/db
3282 + type = types.port;
3285 + Port on which the "${srv}" backend should listen.
3289 - # Update copy of each users' profile to the latest
3290 - # See https://lists.sr.ht/~sircmpwn/sr.ht-admins/<20190302181207.GA13778%40cirno.my.domain>
3291 - if ! test -e ${statePath}/webhook; then
3292 - # Update ${iniKey}'s users' profile copy to the latest
3293 - ${cfg.python}/bin/srht-update-profiles ${iniKey}
3297 + default = "unix:/run/redis-sourcehut-${srvsrht}/redis.sock?db=0";
3298 + example = "redis://shared.wireguard:6379/0";
3300 + The redis host URL. This is used for caching and temporary storage, and must
3301 + be shared between nodes (e.g. git1.sr.ht and git2.sr.ht), but need not be
3302 + shared between services. It may be shared between services, however, with no
3303 + ill effect, if this better suits your infrastructure.
3308 - touch ${statePath}/webhook
3311 + database = mkOption {
3313 + default = "${srv}.sr.ht";
3315 + PostgreSQL database name for the ${srv}.sr.ht service,
3316 + used if <xref linkend="opt-services.sourcehut.postgresql.enable"/> is <literal>true</literal>.
3321 - ${optionalString (builtins.hasAttr "migrate-on-upgrade" cfgIni && cfgIni.migrate-on-upgrade == "yes") ''
3322 - if [ "$(cat ${statePath}/db)" != "${serviceDrv.version}" ]; then
3323 - # Manage schema migrations using alembic
3324 - ${cfg.python}/bin/${serviceDrv.pname}-migrate -a upgrade head
3326 + extraArgs = mkOption {
3327 + type = with types; listOf str;
3328 + default = ["--timeout 120" "--workers 1" "--log-level=info"];
3329 + description = "Extra arguments passed to Gunicorn.";
3332 + } // optionalAttrs webhooks {
3334 + extraArgs = mkOption {
3335 + type = with types; listOf str;
3336 + default = ["--loglevel DEBUG" "--pool eventlet" "--without-heartbeat"];
3337 + description = "Extra arguments passed to the Celery responsible for webhooks.";
3339 + celeryConfig = mkOption {
3340 + type = types.lines;
3342 + description = "Content of the <literal>celeryconfig.py</literal> used by the Celery responsible for webhooks.";
3347 - # Mark down current package version
3348 - printf "%s" "${serviceDrv.version}" > ${statePath}/db
3351 + config = lib.mkIf (cfg.enable && srvCfg.enable) (mkMerge [ extraConfig {
3354 + "${srvCfg.user}" = {
3355 + isSystemUser = true;
3356 + group = mkDefault srvCfg.group;
3357 + description = mkDefault "sourcehut user for ${srv}.sr.ht";
3361 + "${srvCfg.group}" = { };
3362 + } // optionalAttrs (cfg.postgresql.enable
3363 + && hasSuffix "0" (postgresql.settings.unix_socket_permissions or "")) {
3364 + "postgres".members = [ srvCfg.user ];
3365 + } // optionalAttrs (cfg.redis.enable
3366 + && hasSuffix "0" (redis.settings.unixsocketperm or "")) {
3367 + "redis-sourcehut-${srvsrht}".members = [ srvCfg.user ];
3371 - ${attrs.preStart or ""}
3373 + services.nginx = mkIf cfg.nginx.enable {
3374 + virtualHosts."${srv}.${cfg.settings."sr.ht".global-domain}" = mkMerge [ {
3375 + forceSSL = mkDefault true;
3376 + locations."/".proxyPass = "http://${cfg.listenAddress}:${toString srvCfg.port}";
3377 + locations."/static" = {
3378 + root = "${pkgs.sourcehut.${srvsrht}}/${pkgs.sourcehut.python.sitePackages}/${srvsrht}";
3379 + extraConfig = mkDefault ''
3383 + } cfg.nginx.virtualHost ];
3386 + services.postgresql = mkIf cfg.postgresql.enable {
3387 + authentication = ''
3388 + local ${srvCfg.postgresql.database} ${srvCfg.user} trust
3390 + ensureDatabases = [ srvCfg.postgresql.database ];
3391 + ensureUsers = map (name: {
3393 + ensurePermissions = { "DATABASE \"${srvCfg.postgresql.database}\"" = "ALL PRIVILEGES"; };
3397 + services.sourcehut.services = mkDefault (filter (s: cfg.${s}.enable)
3398 + [ "builds" "dispatch" "git" "hg" "hub" "lists" "man" "meta" "pages" "paste" "todo" ]);
3400 + services.sourcehut.settings = mkMerge [
3402 + "${srv}.sr.ht".origin = mkDefault "https://${srv}.${cfg.settings."sr.ht".global-domain}";
3405 + (mkIf cfg.postgresql.enable {
3406 + "${srv}.sr.ht".connection-string = mkDefault "postgresql:///${srvCfg.postgresql.database}?user=${srvCfg.user}&host=/run/postgresql";
3410 + services.redis.servers."sourcehut-${srvsrht}" = mkIf cfg.redis.enable {
3414 + # TODO: set a more informed value
3415 + save = mkDefault [ [1800 10] [300 100] ];
3417 + # TODO: set a more informed value
3418 + maxmemory = "128MB";
3419 + maxmemory-policy = "volatile-ttl";
3423 + systemd.services = mkMerge [
3425 + "${srvsrht}" = baseService srvsrht { allowStripe = srv == "meta"; } (mkMerge [
3427 + description = "sourcehut ${srv}.sr.ht website service";
3428 + before = optional cfg.nginx.enable "nginx.service";
3429 + wants = optional cfg.nginx.enable "nginx.service";
3430 + wantedBy = [ "multi-user.target" ];
3431 + path = optional cfg.postgresql.enable postgresql.package;
3432 + # Beware: change in credentials' content will not trigger restart.
3433 + restartTriggers = [ configIni ];
3436 + Restart = mkDefault "always";
3437 + #RestartSec = mkDefault "2min";
3438 + StateDirectory = [ "sourcehut/${srvsrht}" ];
3439 + StateDirectoryMode = "2750";
3440 + ExecStart = "${cfg.python}/bin/gunicorn ${srvsrht}.app:app --name ${srvsrht} --bind ${cfg.listenAddress}:${toString srvCfg.port} " + concatStringsSep " " srvCfg.gunicorn.extraArgs;
3443 + version = pkgs.sourcehut.${srvsrht}.version;
3444 + stateDir = "/var/lib/sourcehut/${srvsrht}";
3447 + # Use the /run/sourcehut/${srvsrht}/config.ini
3448 + # installed by a previous ExecStartPre= in baseService
3449 + cd /run/sourcehut/${srvsrht}
3451 + if test ! -e ${stateDir}/db; then
3452 + # Setup the initial database.
3453 + # Note that it stamps the alembic head afterward
3454 + ${cfg.python}/bin/${srvsrht}-initdb
3455 + echo ${version} >${stateDir}/db
3458 + ${optionalString cfg.settings.${iniKey}.migrate-on-upgrade ''
3459 + if [ "$(cat ${stateDir}/db)" != "${version}" ]; then
3460 + # Manage schema migrations using alembic
3461 + ${cfg.python}/bin/${srvsrht}-migrate -a upgrade head
3462 + echo ${version} >${stateDir}/db
3466 + # Update copy of each users' profile to the latest
3467 + # See https://lists.sr.ht/~sircmpwn/sr.ht-admins/<20190302181207.GA13778%40cirno.my.domain>
3468 + if test ! -e ${stateDir}/webhook; then
3469 + # Update ${iniKey}'s users' profile copy to the latest
3470 + ${cfg.python}/bin/srht-update-profiles ${iniKey}
3471 + touch ${stateDir}/webhook
3478 + "${srvsrht}-webhooks" = baseService "${srvsrht}-webhooks" {}
3480 + description = "sourcehut ${srv}.sr.ht webhooks service";
3481 + after = [ "${srvsrht}.service" ];
3482 + wantedBy = [ "${srvsrht}.service" ];
3483 + partOf = [ "${srvsrht}.service" ];
3485 + cp ${pkgs.writeText "${srvsrht}-webhooks-celeryconfig.py" srvCfg.webhooks.celeryConfig} \
3486 + /run/sourcehut/${srvsrht}-webhooks/celeryconfig.py
3490 + Restart = "always";
3491 + ExecStart = "${cfg.python}/bin/celery --app ${srvsrht}.webhooks worker --hostname ${srvsrht}-webhooks@%%h " + concatStringsSep " " srvCfg.webhooks.extraArgs;
3492 + # Avoid crashing: os.getloadavg()
3493 + ProcSubset = mkForce "all";
3498 + (mapAttrs (timerName: timer: (baseService timerName {} (mkMerge [
3500 + description = "sourcehut ${timerName} service";
3501 + after = [ "network.target" "${srvsrht}.service" ];
3504 + ExecStart = "${cfg.python}/bin/${timerName}";
3507 + (timer.service or {})
3510 + (mapAttrs (serviceName: extraService: baseService serviceName {} (mkMerge [
3512 + description = "sourcehut ${serviceName} service";
3513 + # So that extraServices have the PostgreSQL database initialized.
3514 + after = [ "${srvsrht}.service" ];
3515 + wantedBy = [ "${srvsrht}.service" ];
3516 + partOf = [ "${srvsrht}.service" ];
3519 + Restart = mkDefault "always";
3523 + ])) extraServices)
3526 + systemd.timers = mapAttrs (timerName: timer:
3528 + description = "sourcehut timer for ${timerName}";
3529 + wantedBy = [ "timers.target" ];
3530 + inherit (timer) timerConfig;
3534 - (builtins.removeAttrs attrs [ "path" "preStart" ])
3535 diff --git a/nixos/modules/services/misc/sourcehut/sourcehut.xml b/nixos/modules/services/misc/sourcehut/sourcehut.xml
3536 index ab9a8c6cb4b..41094f65a94 100644
3537 --- a/nixos/modules/services/misc/sourcehut/sourcehut.xml
3538 +++ b/nixos/modules/services/misc/sourcehut/sourcehut.xml
3540 <title>Basic usage</title>
3542 Sourcehut is a Python and Go based set of applications.
3543 - <literal><link linkend="opt-services.sourcehut.enable">services.sourcehut</link></literal>
3544 - by default will use
3545 + This NixOS module also provides basic configuration integrating Sourcehut into locally running
3546 <literal><link linkend="opt-services.nginx.enable">services.nginx</link></literal>,
3547 - <literal><link linkend="opt-services.nginx.enable">services.redis</link></literal>,
3548 - <literal><link linkend="opt-services.nginx.enable">services.cron</link></literal>,
3549 + <literal><link linkend="opt-services.redis.servers">services.redis.servers.sourcehut</link></literal>,
3550 + <literal><link linkend="opt-services.postfix.enable">services.postfix</link></literal>
3552 - <literal><link linkend="opt-services.postgresql.enable">services.postgresql</link></literal>.
3553 + <literal><link linkend="opt-services.postgresql.enable">services.postgresql</link></literal> services.
3557 @@ -42,18 +41,23 @@ in {
3559 services.sourcehut = {
3560 <link linkend="opt-services.sourcehut.enable">enable</link> = true;
3561 - <link linkend="opt-services.sourcehut.originBase">originBase</link> = fqdn;
3562 - <link linkend="opt-services.sourcehut.services">services</link> = [ "meta" "man" "git" ];
3563 + <link linkend="opt-services.sourcehut.git.enable">git.enable</link> = true;
3564 + <link linkend="opt-services.sourcehut.man.enable">man.enable</link> = true;
3565 + <link linkend="opt-services.sourcehut.meta.enable">meta.enable</link> = true;
3566 + <link linkend="opt-services.sourcehut.nginx.enable">nginx.enable</link> = true;
3567 + <link linkend="opt-services.sourcehut.postfix.enable">postfix.enable</link> = true;
3568 + <link linkend="opt-services.sourcehut.postgresql.enable">postgresql.enable</link> = true;
3569 + <link linkend="opt-services.sourcehut.redis.enable">redis.enable</link> = true;
3570 <link linkend="opt-services.sourcehut.settings">settings</link> = {
3572 environment = "production";
3573 global-domain = fqdn;
3574 origin = "https://${fqdn}";
3575 # Produce keys with srht-keygen from <package>sourcehut.coresrht</package>.
3576 - network-key = "SECRET";
3577 - service-key = "SECRET";
3578 + network-key = "/run/keys/path/to/network-key";
3579 + service-key = "/run/keys/path/to/service-key";
3581 - webhooks.private-key= "SECRET";
3582 + webhooks.private-key= "/run/keys/path/to/webhook-key";
3586 diff --git a/nixos/modules/services/misc/sourcehut/todo.nix b/nixos/modules/services/misc/sourcehut/todo.nix
3587 deleted file mode 100644
3588 index aec773b0669..00000000000
3589 --- a/nixos/modules/services/misc/sourcehut/todo.nix
3592 -{ config, lib, pkgs, ... }:
3596 - cfg = config.services.sourcehut;
3597 - cfgIni = cfg.settings;
3599 - iniKey = "todo.sr.ht";
3601 - rcfg = config.services.redis;
3602 - drv = pkgs.sourcehut.todosrht;
3605 - options.services.sourcehut.todo = {
3608 - default = "todosrht";
3610 - User for todo.sr.ht.
3615 - type = types.port;
3618 - Port on which the "todo" module should listen.
3622 - database = mkOption {
3624 - default = "todo.sr.ht";
3626 - PostgreSQL database name for todo.sr.ht.
3630 - statePath = mkOption {
3631 - type = types.path;
3632 - default = "${cfg.statePath}/todosrht";
3634 - State path for todo.sr.ht.
3639 - config = with scfg; lib.mkIf (cfg.enable && elem "todo" cfg.services) {
3643 - isSystemUser = true;
3645 - extraGroups = [ "postfix" ];
3646 - description = "todo.sr.ht user";
3654 - services.postgresql = {
3655 - authentication = ''
3656 - local ${database} ${user} trust
3658 - ensureDatabases = [ database ];
3662 - ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
3668 - tmpfiles.rules = [
3669 - "d ${statePath} 0750 ${user} ${user} -"
3673 - todosrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
3674 - after = [ "postgresql.service" "network.target" ];
3675 - requires = [ "postgresql.service" ];
3676 - wantedBy = [ "multi-user.target" ];
3678 - description = "todo.sr.ht website service";
3680 - serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
3684 - after = [ "postgresql.service" "network.target" ];
3685 - bindsTo = [ "postgresql.service" ];
3686 - wantedBy = [ "multi-user.target" ];
3688 - description = "todo.sr.ht process service";
3692 - Restart = "always";
3693 - ExecStart = "${cfg.python}/bin/todosrht-lmtp";
3697 - todosrht-webhooks = {
3698 - after = [ "postgresql.service" "network.target" ];
3699 - requires = [ "postgresql.service" ];
3700 - wantedBy = [ "multi-user.target" ];
3702 - description = "todo.sr.ht webhooks service";
3706 - Restart = "always";
3707 - ExecStart = "${cfg.python}/bin/celery -A ${drv.pname}.webhooks worker --loglevel=info";
3714 - services.sourcehut.settings = {
3715 - # URL todo.sr.ht is being served at (protocol://domain)
3716 - "todo.sr.ht".origin = mkDefault "http://todo.${cfg.originBase}";
3717 - # Address and port to bind the debug server to
3718 - "todo.sr.ht".debug-host = mkDefault "0.0.0.0";
3719 - "todo.sr.ht".debug-port = mkDefault port;
3720 - # Configures the SQLAlchemy connection string for the database.
3721 - "todo.sr.ht".connection-string = mkDefault "postgresql:///${database}?user=${user}&host=/var/run/postgresql";
3722 - # Set to "yes" to automatically run migrations on package upgrade.
3723 - "todo.sr.ht".migrate-on-upgrade = mkDefault "yes";
3724 - # todo.sr.ht's OAuth client ID and secret for meta.sr.ht
3725 - # Register your client at meta.example.org/oauth
3726 - "todo.sr.ht".oauth-client-id = mkDefault null;
3727 - "todo.sr.ht".oauth-client-secret = mkDefault null;
3728 - # Outgoing email for notifications generated by users
3729 - "todo.sr.ht".notify-from = mkDefault "CHANGEME@example.org";
3730 - # The redis connection used for the webhooks worker
3731 - "todo.sr.ht".webhooks = mkDefault "redis://${rcfg.bind}:${toString rcfg.port}/1";
3733 - "todo.sr.ht".network-key = mkDefault null;
3735 - # Path for the lmtp daemon's unix socket. Direct incoming mail to this socket.
3736 - # Alternatively, specify IP:PORT and an SMTP server will be run instead.
3737 - "todo.sr.ht::mail".sock = mkDefault "/tmp/todo.sr.ht-lmtp.sock";
3738 - # The lmtp daemon will make the unix socket group-read/write for users in this
3740 - "todo.sr.ht::mail".sock-group = mkDefault "postfix";
3742 - "todo.sr.ht::mail".posting-domain = mkDefault "todo.${cfg.originBase}";
3745 - services.nginx.virtualHosts."todo.${cfg.originBase}" = {
3747 - locations."/".proxyPass = "http://${cfg.address}:${toString port}";
3748 - locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
3749 - locations."/static".root = "${pkgs.sourcehut.todosrht}/${pkgs.sourcehut.python.sitePackages}/todosrht";
3753 diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix
3754 index f86cc2544da..0ccd312b304 100644
3755 --- a/nixos/tests/all-tests.nix
3756 +++ b/nixos/tests/all-tests.nix
3757 @@ -432,6 +432,7 @@ in
3758 solanum = handleTest ./solanum.nix {};
3759 solr = handleTest ./solr.nix {};
3760 sonarr = handleTest ./sonarr.nix {};
3761 + sourcehut = handleTest ./sourcehut.nix {};
3762 spacecookie = handleTest ./spacecookie.nix {};
3763 spark = handleTestOn ["x86_64-linux"] ./spark {};
3764 sslh = handleTest ./sslh.nix {};
3765 diff --git a/nixos/tests/sourcehut.nix b/nixos/tests/sourcehut.nix
3766 index b56a14ebf85..d1536c59322 100644
3767 --- a/nixos/tests/sourcehut.nix
3768 +++ b/nixos/tests/sourcehut.nix
3770 -import ./make-test-python.nix ({ pkgs, ... }:
3771 +import ./make-test-python.nix ({ pkgs, lib, ... }:
3773 + domain = "sourcehut.localdomain";
3775 + # Note that wildcard certificates just under the TLD (eg. *.com)
3776 + # would be rejected by clients like curl.
3777 + tls-cert = pkgs.runCommand "selfSignedCerts" { buildInputs = [ pkgs.openssl ]; } ''
3778 + openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -nodes -days 36500 \
3779 + -subj '/CN=${domain}' -extensions v3_req \
3780 + -addext 'subjectAltName = DNS:*.${domain}'
3781 + install -D -t $out key.pem cert.pem
3785 + nixos.unstable.x86_64 =
3787 + systemConfig = { pkgs, ... }: {
3788 + # passwordless ssh server
3789 + services.openssh = {
3791 + permitRootLogin = "yes";
3792 + extraConfig = "PermitEmptyPasswords yes";
3796 + mutableUsers = false;
3798 + extraUsers."build" = {
3799 + isNormalUser = true;
3801 + extraGroups = [ "wheel" ];
3804 + users.root.password = "";
3807 + security.sudo.wheelNeedsPassword = false;
3808 + nix.trustedUsers = [ "root" "build" ];
3809 + documentation.nixos.enable = false;
3811 + # builds.sr.ht-image-specific network settings
3813 + hostName = "build";
3814 + dhcpcd.enable = false;
3815 + defaultGateway.address = "10.0.2.2";
3816 + usePredictableInterfaceNames = false;
3817 + interfaces."eth0".ipv4.addresses = [{
3818 + address = "10.0.2.15";
3819 + prefixLength = 25;
3821 + enableIPv6 = false;
3829 + firewall.allowedTCPPorts = [ 22 ];
3832 + environment.systemPackages = [
3839 + qemuConfig = { pkgs, ... }: {
3840 + imports = [ systemConfig ];
3841 + fileSystems."/".device = "/dev/disk/by-label/nixos";
3842 + boot.initrd.availableKernelModules = [
3857 + device = "/dev/vda";
3862 + config = (import (pkgs.path + "/nixos/lib/eval-config.nix") {
3863 + inherit pkgs; modules = [ qemuConfig ];
3864 + system = "x86_64-linux";
3867 + import (pkgs.path + "/nixos/lib/make-disk-image.nix") {
3868 + inherit pkgs lib config;
3870 + format = "qcow2-compressed";
3872 + { source = pkgs.writeText "gitconfig" ''
3874 + name = builds.sr.ht
3875 + email = build@sr.ht
3877 + target = "/home/build/.gitconfig";
3890 meta.maintainers = [ pkgs.lib.maintainers.tomberek ];
3892 - machine = { config, pkgs, ... }: {
3893 - virtualisation.memorySize = 2048;
3894 - networking.firewall.allowedTCPPorts = [ 80 ];
3895 + machine = { config, pkgs, nodes, ... }: {
3896 + # buildsrht needs space
3897 + virtualisation.diskSize = 4 * 1024;
3898 + virtualisation.memorySize = 2 * 1024;
3899 + networking.domain = domain;
3900 + networking.extraHosts = ''
3901 + ${config.networking.primaryIPAddress} meta.${domain}
3902 + ${config.networking.primaryIPAddress} builds.${domain}
3905 services.sourcehut = {
3907 - services = [ "meta" ];
3908 - originBase = "sourcehut";
3909 - settings."sr.ht".service-key = "8888888888888888888888888888888888888888888888888888888888888888";
3910 - settings."sr.ht".network-key = "0000000000000000000000000000000000000000000=";
3911 - settings.webhooks.private-key = "0000000000000000000000000000000000000000000=";
3912 + services = [ "meta" "builds" ];
3913 + nginx.enable = true;
3914 + nginx.virtualHost = {
3916 + sslCertificate = "${tls-cert}/cert.pem";
3917 + sslCertificateKey = "${tls-cert}/key.pem";
3919 + postgresql.enable = true;
3920 + redis.enable = true;
3922 + meta.enable = true;
3925 + # FIXME: see why it does not seem to activate fully.
3926 + #enableWorker = true;
3929 + settings."sr.ht" = {
3930 + global-domain = config.networking.domain;
3931 + service-key = pkgs.writeText "service-key" "8b327279b77e32a3620e2fc9aabce491cc46e7d821fd6713b2a2e650ce114d01";
3932 + network-key = pkgs.writeText "network-key" "cEEmc30BRBGkgQZcHFksiG7hjc6_dK1XR2Oo5Jb9_nQ=";
3934 + settings."builds.sr.ht" = {
3935 + oauth-client-secret = pkgs.writeText "buildsrht-oauth-client-secret" "2260e9c4d9b8dcedcef642860e0504bc";
3936 + oauth-client-id = "299db9f9c2013170";
3938 + settings.webhooks.private-key = pkgs.writeText "webhook-key" "Ra3IjxgFiwG9jxgp4WALQIZw/BMYt30xWiOsqD0J7EA=";
3941 + networking.firewall.allowedTCPPorts = [ 443 ];
3942 + security.pki.certificateFiles = [ "${tls-cert}/cert.pem" ];
3943 + services.nginx = {
3945 + recommendedGzipSettings = true;
3946 + recommendedOptimisation = true;
3947 + recommendedTlsSettings = true;
3948 + recommendedProxySettings = true;
3951 + services.postgresql = {
3953 + enableTCPIP = false;
3954 + settings.unix_socket_permissions = "0770";
3960 machine.wait_for_unit("multi-user.target")
3962 + # Testing metasrht
3963 + machine.wait_for_unit("metasrht-api.service")
3964 machine.wait_for_unit("metasrht.service")
3965 machine.wait_for_open_port(5000)
3966 - machine.succeed("curl -sL http://localhost:5000 | grep meta.sourcehut")
3967 + machine.succeed("curl -sL http://localhost:5000 | grep meta.${domain}")
3968 + machine.succeed("curl -sL http://meta.${domain} | grep meta.${domain}")
3970 + # Testing buildsrht
3971 + machine.wait_for_unit("buildsrht.service")
3972 + machine.wait_for_open_port(5002)
3973 + machine.succeed("curl -sL http://localhost:5002 | grep builds.${domain}")
3974 + #machine.wait_for_unit("buildsrht-worker.service")
3977 diff --git a/pkgs/applications/version-management/sourcehut/builds.nix b/pkgs/applications/version-management/sourcehut/builds.nix
3978 index c8163caf8ea..df0df206573 100644
3979 --- a/pkgs/applications/version-management/sourcehut/builds.nix
3980 +++ b/pkgs/applications/version-management/sourcehut/builds.nix
3985 - version = "0.66.7";
3986 + version = "0.74.2";
3988 + src = fetchFromSourcehut {
3989 + owner = "~sircmpwn";
3990 + repo = "builds.sr.ht";
3992 + sha256 = "sha256-vdVKaI42pA0dnyMXhQ4AEaDgTtKcrH6hc9L6PFcl6ZA=";
3995 buildWorker = src: buildGoModule {
3996 inherit src version;
3997 pname = "builds-sr-ht-worker";
3999 - vendorSha256 = "sha256-giOaldV46aBqXyFH/cQVsbUr6Rb4VMhbBO86o48tRZY=";
4000 + vendorSha256 = "sha256-ZEarWM/33t+pNXUEIpfd/DkBkhu3UUg17Hh8XXWOepA=";
4003 buildPythonPackage rec {
4004 @@ -28,7 +35,7 @@ buildPythonPackage rec {
4005 owner = "~sircmpwn";
4006 repo = "builds.sr.ht";
4008 - sha256 = "sha256-2MLs/DOXHjEYarXDVUcPZe3o0fmZbzVxn528SE72lhM=";
4009 + sha256 = "sha256-c2xp2uIP8+WeRMz0efA1H58Nkot65bc03e7rrrZk3jo=";
4012 nativeBuildInputs = srht.nativeBuildInputs;
4013 @@ -56,10 +63,12 @@ buildPythonPackage rec {
4014 cp ${buildWorker "${src}/worker"}/bin/worker $out/bin/builds.sr.ht-worker
4017 + pythonImportsCheck = [ "buildsrht" ];
4020 homepage = "https://git.sr.ht/~sircmpwn/builds.sr.ht";
4021 description = "Continuous integration service for the sr.ht network";
4022 - license = licenses.agpl3;
4023 + license = licenses.agpl3Only;
4024 maintainers = with maintainers; [ eadwu ];
4027 diff --git a/pkgs/applications/version-management/sourcehut/core.nix b/pkgs/applications/version-management/sourcehut/core.nix
4028 index 7c3a516ed9d..d5bbd2927b6 100644
4029 --- a/pkgs/applications/version-management/sourcehut/core.nix
4030 +++ b/pkgs/applications/version-management/sourcehut/core.nix
4038 buildPythonPackage rec {
4040 - version = "0.67.4";
4041 + version = "0.68.2";
4044 url = "https://git.sr.ht/~sircmpwn/core.sr.ht";
4046 - sha256 = "sha256-XvzFfcBK5Mq8p7xEBAF/eupUE1kkUBh5k+ByM/WA9bc=";
4047 + sha256 = "sha256-vLdKJgi3arF5PSODbCSCX7fWGZfgkOirGSdYzcNXRdk=";
4048 fetchSubmodules = true;
4051 @@ -46,6 +45,7 @@ buildPythonPackage rec {
4055 + # Disable check for npm
4056 ./disable-npm-install.patch
4059 @@ -87,6 +87,7 @@ buildPythonPackage rec {
4062 dontUseSetuptoolsCheck = true;
4063 + pythonImportsCheck = [ "srht" ];
4066 homepage = "https://git.sr.ht/~sircmpwn/srht";
4067 diff --git a/pkgs/applications/version-management/sourcehut/default.nix b/pkgs/applications/version-management/sourcehut/default.nix
4068 index 401a1437b7d..00810f208cc 100644
4069 --- a/pkgs/applications/version-management/sourcehut/default.nix
4070 +++ b/pkgs/applications/version-management/sourcehut/default.nix
4071 @@ -22,6 +22,7 @@ let
4072 listssrht = self.callPackage ./lists.nix { };
4073 mansrht = self.callPackage ./man.nix { };
4074 metasrht = self.callPackage ./meta.nix { };
4075 + pagessrht = self.callPackage ./pages.nix { };
4076 pastesrht = self.callPackage ./paste.nix { };
4077 todosrht = self.callPackage ./todo.nix { };
4079 @@ -40,6 +41,7 @@ with python.pkgs; recurseIntoAttrs {
4080 listssrht = toPythonApplication listssrht;
4081 mansrht = toPythonApplication mansrht;
4082 metasrht = toPythonApplication metasrht;
4083 + pagessrht = pagessrht;
4084 pastesrht = toPythonApplication pastesrht;
4085 todosrht = toPythonApplication todosrht;
4087 diff --git a/pkgs/applications/version-management/sourcehut/dispatch.nix b/pkgs/applications/version-management/sourcehut/dispatch.nix
4088 index 637c6f9c1df..9456d0c998c 100644
4089 --- a/pkgs/applications/version-management/sourcehut/dispatch.nix
4090 +++ b/pkgs/applications/version-management/sourcehut/dispatch.nix
4093 buildPythonPackage rec {
4094 pname = "dispatchsrht";
4095 - version = "0.15.8";
4096 + version = "0.15.32";
4098 src = fetchFromSourcehut {
4099 owner = "~sircmpwn";
4100 repo = "dispatch.sr.ht";
4102 - sha256 = "sha256-zWCGPjIgMKHXHJUs9aciV7IFgo0rpahon6KXHDwcfss=";
4103 + sha256 = "sha256-4P4cXhjcZ8IBzpRfmYIJkzl9U4Plo36a48Pf/KjmhFY=";
4106 nativeBuildInputs = srht.nativeBuildInputs;
4107 @@ -31,10 +31,12 @@ buildPythonPackage rec {
4108 export SRHT_PATH=${srht}/${python.sitePackages}/srht
4111 + pythonImportsCheck = [ "dispatchsrht" ];
4114 homepage = "https://dispatch.sr.ht/~sircmpwn/dispatch.sr.ht";
4115 description = "Task dispatcher and service integration tool for the sr.ht network";
4116 - license = licenses.agpl3;
4117 + license = licenses.agpl3Only;
4118 maintainers = with maintainers; [ eadwu ];
4121 diff --git a/pkgs/applications/version-management/sourcehut/git.nix b/pkgs/applications/version-management/sourcehut/git.nix
4122 index e44fb9cd6c6..1ec331f4353 100644
4123 --- a/pkgs/applications/version-management/sourcehut/git.nix
4124 +++ b/pkgs/applications/version-management/sourcehut/git.nix
4129 - version = "0.72.8";
4130 + version = "0.73.6";
4132 src = fetchFromSourcehut {
4133 owner = "~sircmpwn";
4136 - sha256 = "sha256-AB2uzajO5PtcpJfbOOTfuDFM6is5K39v3AZJ1hShRNc=";
4137 + sha256 = "sha256-9WdeHXmyX5K/ldaE9AbSWTRlsrSDuKtm8QhthEHfmuU=";
4140 buildShell = src: buildGoModule {
4141 @@ -32,12 +32,14 @@ let
4142 buildKeys = src: buildGoModule {
4143 inherit src version;
4144 pname = "gitsrht-keys";
4145 - vendorSha256 = "1d94cqy7x0q0agwg515xxsbl70b3qrzxbzsyjhn1pbyj532brn7f";
4146 + vendorSha256 = "sha256-SOI7wimFthY+BwsDtMuyqKS1hCaEa3R90Q0qaA9boyE=";
4149 buildUpdateHook = src: buildGoModule {
4150 inherit src version;
4151 pname = "gitsrht-update-hook";
4152 + vendorSha256 = "sha256-L/tGwbBSwhtGhHcinCK/0lsp1ffXjiHXCmGgsY9s2Nc=";
4154 vendorSha256 = "0fwzqpjv8x5y3w3bfjd0x0cvqjjak23m0zj88hf32jpw49xmjkih";
4157 @@ -72,10 +74,12 @@ buildPythonPackage rec {
4161 + pythonImportsCheck = [ "gitsrht" ];
4164 homepage = "https://git.sr.ht/~sircmpwn/git.sr.ht";
4165 description = "Git repository hosting service for the sr.ht network";
4166 - license = licenses.agpl3;
4167 + license = licenses.agpl3Only;
4168 maintainers = with maintainers; [ eadwu ];
4171 diff --git a/pkgs/applications/version-management/sourcehut/hg.nix b/pkgs/applications/version-management/sourcehut/hg.nix
4172 index cddb76cabf2..e13b27d4139 100644
4173 --- a/pkgs/applications/version-management/sourcehut/hg.nix
4174 +++ b/pkgs/applications/version-management/sourcehut/hg.nix
4177 buildPythonPackage rec {
4179 - version = "0.27.4";
4180 + version = "0.28.1";
4183 url = "https://hg.sr.ht/~sircmpwn/hg.sr.ht";
4185 - sha256 = "1c0qfi0gmbfngvds6917fy9ii2iglawn429757rh7b4bvzn7n6mr";
4186 + sha256 = "ERMPaCtExZebwV1BrjyE/gGK7p/Nvf7ia+ZBO472bdw=";
4189 nativeBuildInputs = srht.nativeBuildInputs;
4190 @@ -32,10 +32,12 @@ buildPythonPackage rec {
4191 export SRHT_PATH=${srht}/${python.sitePackages}/srht
4194 + pythonImportsCheck = [ "hgsrht" ];
4197 homepage = "https://git.sr.ht/~sircmpwn/hg.sr.ht";
4198 description = "Mercurial repository hosting service for the sr.ht network";
4199 - license = licenses.agpl3;
4200 + license = licenses.agpl3Only;
4201 maintainers = with maintainers; [ eadwu ];
4204 diff --git a/pkgs/applications/version-management/sourcehut/hub.nix b/pkgs/applications/version-management/sourcehut/hub.nix
4205 index 17cb3fe4b61..9c834246def 100644
4206 --- a/pkgs/applications/version-management/sourcehut/hub.nix
4207 +++ b/pkgs/applications/version-management/sourcehut/hub.nix
4210 buildPythonPackage rec {
4212 - version = "0.13.1";
4213 + version = "0.13.16";
4215 src = fetchFromSourcehut {
4216 owner = "~sircmpwn";
4219 - sha256 = "sha256-Kqzy4mh5Nn1emzHBco/LVuXro/tW3NX+OYqdEwBSQ/U=";
4220 + sha256 = "sha256-TyeEJvkRjqTs92+pKloJhpTnnkYaMZHZkdO6Da5Bq7c=";
4223 nativeBuildInputs = srht.nativeBuildInputs;
4224 @@ -26,11 +26,12 @@ buildPythonPackage rec {
4227 dontUseSetuptoolsCheck = true;
4228 + pythonImportsCheck = [ "hubsrht" ];
4231 homepage = "https://git.sr.ht/~sircmpwn/hub.sr.ht";
4232 description = "Project hub service for the sr.ht network";
4233 - license = licenses.agpl3;
4234 + license = licenses.agpl3Only;
4235 maintainers = with maintainers; [ eadwu ];
4238 diff --git a/pkgs/applications/version-management/sourcehut/lists.nix b/pkgs/applications/version-management/sourcehut/lists.nix
4239 index b419b49f7b5..4ffc2ac9dee 100644
4240 --- a/pkgs/applications/version-management/sourcehut/lists.nix
4241 +++ b/pkgs/applications/version-management/sourcehut/lists.nix
4244 buildPythonPackage rec {
4245 pname = "listssrht";
4246 - version = "0.48.19";
4247 + version = "0.50.2";
4249 src = fetchFromSourcehut {
4250 owner = "~sircmpwn";
4251 repo = "lists.sr.ht";
4253 - sha256 = "sha256-bsakEMyvWaxiE4/SGcAP4mlGG9jkdHfFxpt9H+TJn/8=";
4254 + sha256 = "sha256-2NO6WJCOwCqGuICnn425NbnemTm8vYBltJyrveUt1n0=";
4257 nativeBuildInputs = srht.nativeBuildInputs;
4258 @@ -37,10 +37,12 @@ buildPythonPackage rec {
4259 export SRHT_PATH=${srht}/${python.sitePackages}/srht
4262 + pythonImportsCheck = [ "listssrht" ];
4265 homepage = "https://git.sr.ht/~sircmpwn/lists.sr.ht";
4266 description = "Mailing list service for the sr.ht network";
4267 - license = licenses.agpl3;
4268 + license = licenses.agpl3Only;
4269 maintainers = with maintainers; [ eadwu ];
4272 diff --git a/pkgs/applications/version-management/sourcehut/man.nix b/pkgs/applications/version-management/sourcehut/man.nix
4273 index bd331f000a7..2d4d152e3aa 100644
4274 --- a/pkgs/applications/version-management/sourcehut/man.nix
4275 +++ b/pkgs/applications/version-management/sourcehut/man.nix
4278 buildPythonPackage rec {
4280 - version = "0.15.12";
4281 + version = "0.15.22";
4283 src = fetchFromSourcehut {
4284 owner = "~sircmpwn";
4287 - sha256 = "sha256-MqH/8K9XRvEg6P7GHE6XXtWnhDP3wT8iGoNaFtYQbio=";
4288 + sha256 = "sha256-curouf+eNCKprDI23blGs4AzJMry6zlCLDt/+0j5c8A=";
4291 nativeBuildInputs = srht.nativeBuildInputs;
4292 @@ -29,10 +29,12 @@ buildPythonPackage rec {
4293 export SRHT_PATH=${srht}/${python.sitePackages}/srht
4296 + pythonImportsCheck = [ "mansrht" ];
4299 homepage = "https://git.sr.ht/~sircmpwn/man.sr.ht";
4300 description = "Wiki service for the sr.ht network";
4301 - license = licenses.agpl3;
4302 + license = licenses.agpl3Only;
4303 maintainers = with maintainers; [ eadwu ];
4306 diff --git a/pkgs/applications/version-management/sourcehut/meta.nix b/pkgs/applications/version-management/sourcehut/meta.nix
4307 index 86d293973d7..96ea83a4ef3 100644
4308 --- a/pkgs/applications/version-management/sourcehut/meta.nix
4309 +++ b/pkgs/applications/version-management/sourcehut/meta.nix
4314 - version = "0.53.14";
4315 + version = "0.56.19";
4317 src = fetchFromSourcehut {
4318 owner = "~sircmpwn";
4319 repo = "meta.sr.ht";
4321 - sha256 = "sha256-/+r/XLDkcSTW647xPMh5bcJmR2xZNNH74AJ5jemna2k=";
4322 + sha256 = "sha256-YVj+aehO+2cJGvti9KXexm3y/0dx3rZBjEf0tKFC+s4=";
4325 buildApi = src: buildGoModule {
4326 inherit src version;
4327 pname = "metasrht-api";
4328 - vendorSha256 = "sha256-eZyDrr2VcNMxI++18qUy7LA1Q1YDlWCoRtl00L8lfR4=";
4329 + vendorSha256 = "sha256-j++Z+QXwCC7H3OK0sfWZrFluOVdN+b2tGCpLnmjKjc4=";
4333 @@ -66,10 +66,12 @@ buildPythonPackage rec {
4334 cp ${buildApi "${src}/api/"}/bin/api $out/bin/metasrht-api
4337 + pythonImportsCheck = [ "metasrht" ];
4340 homepage = "https://git.sr.ht/~sircmpwn/meta.sr.ht";
4341 description = "Account management service for the sr.ht network";
4342 - license = licenses.agpl3;
4343 + license = licenses.agpl3Only;
4344 maintainers = with maintainers; [ eadwu ];
4347 diff --git a/pkgs/applications/version-management/sourcehut/pages.nix b/pkgs/applications/version-management/sourcehut/pages.nix
4348 new file mode 100644
4349 index 00000000000..c49e49c2664
4351 +++ b/pkgs/applications/version-management/sourcehut/pages.nix
4354 +, fetchFromSourcehut
4358 +buildGoModule rec {
4359 + pname = "pagessrht";
4360 + version = "0.5.1";
4362 + src = fetchFromSourcehut {
4363 + owner = "~sircmpwn";
4364 + repo = "pages.sr.ht";
4366 + sha256 = "sha256-Cab8zx+9WHHAB1rBoyZACq7lx9JdRBGzI1H+Yu9qHfs=";
4369 + vendorSha256 = "sha256-udr+1y5ApQCSPhs3yQTTi9QfzRbz0A9COYuFMjQGa74=";
4372 + mkdir -p $out/share/sql/
4373 + cp -r -t $out/share/sql/ schema.sql migrations
4376 + meta = with lib; {
4377 + homepage = "https://git.sr.ht/~sircmpwn/pages.sr.ht";
4378 + description = "Web hosting service for the sr.ht network";
4379 + license = licenses.agpl3Only;
4380 + maintainers = with maintainers; [ eadwu ];
4383 diff --git a/pkgs/applications/version-management/sourcehut/paste.nix b/pkgs/applications/version-management/sourcehut/paste.nix
4384 index 0d8c9135493..c411f8e8c95 100644
4385 --- a/pkgs/applications/version-management/sourcehut/paste.nix
4386 +++ b/pkgs/applications/version-management/sourcehut/paste.nix
4389 buildPythonPackage rec {
4390 pname = "pastesrht";
4391 - version = "0.12.1";
4392 + version = "0.13.6";
4394 src = fetchFromSourcehut {
4395 owner = "~sircmpwn";
4396 repo = "paste.sr.ht";
4398 - sha256 = "sha256-QQhd2LeH9BLmlHilhsv+9fZ+RPNmEMSmOpFA3dsMBFc=";
4399 + sha256 = "sha256-Khcqk86iD9nxiKXN3+8mSLNoDau2qXNFOrLdkVu+rH8=";
4402 nativeBuildInputs = srht.nativeBuildInputs;
4403 @@ -29,10 +29,12 @@ buildPythonPackage rec {
4404 export SRHT_PATH=${srht}/${python.sitePackages}/srht
4407 + pythonImportsCheck = [ "pastesrht" ];
4410 homepage = "https://git.sr.ht/~sircmpwn/paste.sr.ht";
4411 description = "Ad-hoc text file hosting service for the sr.ht network";
4412 - license = licenses.agpl3;
4413 + license = licenses.agpl3Only;
4414 maintainers = with maintainers; [ eadwu ];
4417 diff --git a/pkgs/applications/version-management/sourcehut/scm.nix b/pkgs/applications/version-management/sourcehut/scm.nix
4418 index 1f385265360..53f899a3d7b 100644
4419 --- a/pkgs/applications/version-management/sourcehut/scm.nix
4420 +++ b/pkgs/applications/version-management/sourcehut/scm.nix
4428 buildPythonPackage rec {
4430 - version = "0.22.9";
4431 + version = "0.22.15";
4433 src = fetchFromSourcehut {
4434 owner = "~sircmpwn";
4437 - sha256 = "sha256-327G6C8FW+iZx+167D7TQsFtV6FGc8MpMVo9L/cUUqU=";
4438 + sha256 = "sha256-h4akgDn78ctBF31TX8D8NwUVUVazClPVvCR9xWyQPBk=";
4441 nativeBuildInputs = srht.nativeBuildInputs;
4442 @@ -33,11 +32,12 @@ buildPythonPackage rec {
4445 dontUseSetuptoolsCheck = true;
4446 + pythonImportsCheck = [ "scmsrht" ];
4449 homepage = "https://git.sr.ht/~sircmpwn/git.sr.ht";
4450 description = "Shared support code for sr.ht source control services.";
4451 - license = licenses.agpl3;
4452 + license = licenses.agpl3Only;
4453 maintainers = with maintainers; [ eadwu ];
4456 diff --git a/pkgs/applications/version-management/sourcehut/todo.nix b/pkgs/applications/version-management/sourcehut/todo.nix
4457 index 85e1f5637b6..cdb1f8cf8be 100644
4458 --- a/pkgs/applications/version-management/sourcehut/todo.nix
4459 +++ b/pkgs/applications/version-management/sourcehut/todo.nix
4462 buildPythonPackage rec {
4464 - version = "0.64.14";
4465 + version = "0.65.2";
4467 src = fetchFromSourcehut {
4468 owner = "~sircmpwn";
4469 repo = "todo.sr.ht";
4471 - sha256 = "sha256-huIAhn6h1F5w5ST4/yBwr82kAzyYwhLu+gpRuOQgnsE=";
4472 + sha256 = "sha256-46RkBwLuGpYYw2V4JBDR414W2EaYnz0rru/T9j/PrJs=";
4475 nativeBuildInputs = srht.nativeBuildInputs;
4476 @@ -42,11 +42,12 @@ buildPythonPackage rec {
4479 dontUseSetuptoolsCheck = true;
4480 + pythonImportsCheck = [ "todosrht" ];
4483 homepage = "https://todo.sr.ht/~sircmpwn/todo.sr.ht";
4484 description = "Ticket tracking service for the sr.ht network";
4485 - license = licenses.agpl3;
4486 + license = licenses.agpl3Only;
4487 maintainers = with maintainers; [ eadwu ];
4490 diff --git a/pkgs/applications/version-management/sourcehut/update.sh b/pkgs/applications/version-management/sourcehut/update.sh
4491 index 156d4cc35e4..104c33a5f4f 100755
4492 --- a/pkgs/applications/version-management/sourcehut/update.sh
4493 +++ b/pkgs/applications/version-management/sourcehut/update.sh
4495 #! /usr/bin/env nix-shell
4496 #! nix-shell -i bash -p git mercurial common-updater-scripts
4497 +set -eux -o pipefail
4499 -cd "$(dirname "${BASH_SOURCE[0]}")"
4500 +cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1
4503 +trap 'rm -rf "$tmp"' EXIT
4506 (cd "$root" && nix-instantiate --eval --strict -A "sourcehut.python.pkgs.$1.meta.position" | sed -re 's/^"(.*):[0-9]+"$/\1/')
4507 @@ -13,42 +16,55 @@ version() {
4511 - (cd "$root" && nix-instantiate --eval --strict -A "sourcehut.python.pkgs.$1.src.drvAttrs.url" | tr -d '"')
4512 + nix-instantiate --eval --strict --expr " with import $root {}; let src = sourcehut.python.pkgs.$1.drvAttrs.src; in src.url or src.meta.homepage" | tr -d '"'
4515 get_latest_version() {
4516 src="$(src_url "$1")"
4520 if [ "$1" = "hgsrht" ]; then
4521 - hg clone "$src" "$tmp" &> /dev/null
4522 + hg clone "$src" "$tmp" >/dev/null
4523 printf "%s" "$(cd "$tmp" && hg log --limit 1 --template '{latesttag}')"
4525 - git clone "$src" "$tmp"
4526 - printf "%s" "$(cd "$tmp" && git describe $(git rev-list --tags --max-count=1))"
4527 + git clone "$src" "$tmp" >/dev/null
4528 + printf "%s" "$(cd "$tmp" && git describe "$(git rev-list --tags --max-count=1)")"
4533 default_nix="$(default "$1")"
4534 - version_old="$(version "$1")"
4535 + oldVersion="$(version "$1")"
4536 version="$(get_latest_version "$1")"
4538 (cd "$root" && update-source-version "sourcehut.python.pkgs.$1" "$version")
4540 - git add "$default_nix"
4541 - git commit -m "$1: $version_old -> $version"
4542 + # Update vendorSha256 of Go modules
4544 + while "$retry"; do
4546 + exec < <(exec nix -L build -f "$root" sourcehut.python.pkgs."$1" 2>&1)
4547 + while IFS=' :' read -r origin hash; do
4549 + (expected|specified) oldHash="$hash";;
4550 + (got) sed -i "s|$oldHash|$hash|" "$default_nix"; retry=true; break;;
4551 + (*) printf >&2 "%s\n" "$origin${hash:+:$hash}"
4556 + if [ "$oldVersion" != "$version" ]; then
4557 + git add "$default_nix"
4558 + git commit -m "sourcehut.$1: $oldVersion -> $version"
4562 -services=( "srht" "buildsrht" "dispatchsrht" "gitsrht" "hgsrht" "hubsrht" "listssrht" "mansrht"
4563 - "metasrht" "pastesrht" "todosrht" "scmsrht" )
4565 -# Whether or not a specific service is requested
4566 -if [ -n "$1" ]; then
4567 - version="$(get_latest_version "$1")"
4568 - (cd "$root" && update-source-version "sourcehut.python.pkgs.$1" "$version")
4569 +if [ $# -gt 0 ]; then
4572 - for service in "${services[@]}"; do
4573 - update_version "$service"
4575 + services=( "srht" "scmsrht" "buildsrht" "dispatchsrht" "gitsrht" "hgsrht" "hubsrht" "listssrht" "mansrht"
4576 + "metasrht" "pagessrht" "pastesrht" "todosrht" )
4579 +for service in "${services[@]}"; do
4580 + update_version "$service"
4582 diff --git a/pkgs/development/go-modules/generic/default.nix b/pkgs/development/go-modules/generic/default.nix
4583 index 3b645f9ce8b..f00ca1984ec 100644
4584 --- a/pkgs/development/go-modules/generic/default.nix
4585 +++ b/pkgs/development/go-modules/generic/default.nix
4586 @@ -71,6 +71,7 @@ let
4587 inherit (go) GOOS GOARCH;
4589 patches = args.patches or [];
4590 + patchFlags = args.patchFlags or [];
4591 preBuild = args.preBuild or "";
4592 sourceRoot = args.sourceRoot or "";