1 { config, lib, pkgs, ... }:
5 cfg = config.services.sourcehut;
9 rcfg = config.services.redis;
10 drv = pkgs.sourcehut.hgsrht;
13 options.services.sourcehut.hg = {
28 Port on which the "hg" module should listen.
36 PostgreSQL database name for hg.sr.ht.
40 statePath = mkOption {
42 default = "${cfg.statePath}/hgsrht";
44 State path for hg.sr.ht.
48 cloneBundles = mkOption {
52 Generate clonebundles (which require more disk space but dramatically speed up cloning large repositories).
57 config = with scfg; lib.mkIf (cfg.enable && elem "hg" cfg.services) {
58 # In case it ever comes into being
59 environment.etc."ssh/hgsrht-dispatch" = {
62 #! ${pkgs.stdenv.shell}
63 ${cfg.python}/bin/gitsrht-dispatch $@
67 environment.systemPackages = [ pkgs.mercurial ];
74 # Assuming hg.sr.ht needs this too
76 description = "hg.sr.ht user";
86 cron.systemCronJobs = [ "*/20 * * * * ${cfg.python}/bin/hgsrht-periodic" ]
87 ++ optional cloneBundles "0 * * * * ${cfg.python}/bin/hgsrht-clonebundles";
89 openssh.authorizedKeysCommand = ''/etc/ssh/hgsrht-dispatch "%u" "%h" "%t" "%k"'';
90 openssh.authorizedKeysCommandUser = "root";
91 openssh.extraConfig = ''
92 PermitUserEnvironment SRHT_*
97 local ${database} ${user} trust
99 ensureDatabases = [ database ];
103 ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
111 # /var/log is owned by root
112 "f /var/log/hg-srht-shell 0644 ${user} ${user} -"
114 "d ${statePath} 0750 ${user} ${user} -"
115 "d ${cfg.settings."${iniKey}".repos} 2755 ${user} ${user} -"
118 services.hgsrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
119 after = [ "redis.service" "postgresql.service" "network.target" ];
120 requires = [ "redis.service" "postgresql.service" ];
121 wantedBy = [ "multi-user.target" ];
123 path = [ pkgs.mercurial ];
124 description = "hg.sr.ht website service";
126 serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
130 services.sourcehut.settings = {
131 # The authorized keys hook uses this to dispatch to various handlers
132 # The format is a program to exec into as the key, and the user to match as the
133 # value. When someone tries to log in as this user, this program is executed
134 # and is expected to omit an AuthorizedKeys file.
136 # Uncomment the relevant lines to enable the various sr.ht dispatchers.
137 "hg.sr.ht::dispatch"."/run/current-system/sw/bin/hgsrht-keys" = mkDefault "${user}:${user}";
140 # TODO: requires testing and addition of hg-specific requirements
141 services.nginx.virtualHosts."hg.${cfg.originBase}" = {
143 locations."/".proxyPass = "http://${cfg.address}:${toString port}";
144 locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
145 locations."/static".root = "${pkgs.sourcehut.hgsrht}/${pkgs.sourcehut.python.sitePackages}/hgsrht";