1 { config, lib, pkgs, ... }:
5 cfg = config.services.sourcehut;
8 statePath = "/var/lib/sourcehut/hgsrht";
10 rcfg = config.services.redis;
11 drv = pkgs.sourcehut.hgsrht;
14 options.services.sourcehut.hg = {
29 Port on which the "hg" module should listen.
37 PostgreSQL database name for hg.sr.ht.
41 cloneBundles = mkOption {
45 Generate clonebundles (which require more disk space but dramatically speed up cloning large repositories).
50 config = with scfg; lib.mkIf (cfg.enable && elem "hg" cfg.services) {
51 # In case it ever comes into being
52 environment.etc."ssh/hgsrht-dispatch" = {
55 #! ${pkgs.stdenv.shell}
56 ${cfg.python}/bin/gitsrht-dispatch $@
60 environment.systemPackages = [ pkgs.mercurial ];
67 # Assuming hg.sr.ht needs this too
69 description = "hg.sr.ht user";
79 cron.systemCronJobs = [ "*/20 * * * * ${cfg.python}/bin/hgsrht-periodic" ]
80 ++ optional cloneBundles "0 * * * * ${cfg.python}/bin/hgsrht-clonebundles";
82 openssh.authorizedKeysCommand = ''/etc/ssh/hgsrht-dispatch "%u" "%h" "%t" "%k"'';
83 openssh.authorizedKeysCommandUser = "root";
84 openssh.extraConfig = ''
85 PermitUserEnvironment SRHT_*
90 local ${database} ${user} trust
92 ensureDatabases = [ database ];
96 ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
104 # /var/log is owned by root
105 "f /var/log/hg-srht-shell 0644 ${user} ${user} -"
107 "d ${cfg.settings."${iniKey}".repos} 2755 ${user} ${user} -"
110 services.hgsrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
111 after = [ "redis.service" "postgresql.service" "network.target" ];
112 requires = [ "redis.service" "postgresql.service" ];
113 wantedBy = [ "multi-user.target" ];
115 path = [ pkgs.mercurial ];
116 description = "hg.sr.ht website service";
118 serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
122 services.sourcehut.settings = {
123 # The authorized keys hook uses this to dispatch to various handlers
124 # The format is a program to exec into as the key, and the user to match as the
125 # value. When someone tries to log in as this user, this program is executed
126 # and is expected to omit an AuthorizedKeys file.
128 # Uncomment the relevant lines to enable the various sr.ht dispatchers.
129 "hg.sr.ht::dispatch"."/run/current-system/sw/bin/hgsrht-keys" = mkDefault "${user}:${user}";
132 # TODO: requires testing and addition of hg-specific requirements
133 services.nginx.virtualHosts."hg.${cfg.originBase}" = {
135 locations."/".proxyPass = "http://${cfg.address}:${toString port}";
136 locations."/query".proxyPass = cfgIni."meta.sr.ht".api-origin;
137 locations."/static".root = "${pkgs.sourcehut.hgsrht}/${pkgs.sourcehut.python.sitePackages}/hgsrht";