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 = {
15 enable = mkEnableOption "git service";
31 Port on which the "hg" module should listen.
39 PostgreSQL database name for hg.sr.ht.
43 cloneBundles = mkOption {
47 Generate clonebundles (which require more disk space but dramatically speed up cloning large repositories).
52 config = with scfg; lib.mkIf (cfg.enable && scfg.enable) {
53 # In case it ever comes into being
54 environment.etc."ssh/hgsrht-dispatch" = {
57 #! ${pkgs.stdenv.shell}
58 ${cfg.python}/bin/gitsrht-dispatch "$@"
62 environment.systemPackages = [ pkgs.mercurial ];
69 # Assuming hg.sr.ht needs this too
71 description = "hg.sr.ht user";
81 openssh.authorizedKeysCommand = ''/etc/ssh/hgsrht-dispatch "%u" "%h" "%t" "%k"'';
82 openssh.authorizedKeysCommandUser = "root";
83 openssh.extraConfig = ''
84 PermitUserEnvironment SRHT_*
89 local ${database} ${user} trust
91 ensureDatabases = [ database ];
95 ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
103 # /var/log is owned by root
104 "f /var/log/hg-srht-shell 0644 ${user} ${user} -"
106 "d ${cfg.settings."${iniKey}".repos} 2755 ${user} ${user} -"
110 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}";
121 hgsrht-periodic = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
122 after = [ "hgsrht.service" ];
123 requires = [ "hgsrht.service" ];
125 description = "hg.sr.ht periodic service";
127 serviceConfig.Type = mkForce "oneshot";
128 serviceConfig.Restart = mkForce "no";
129 serviceConfig.ExecStart = "${cfg.python}/bin/hgsrht-periodic";
132 hgsrht-clonebundles = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
133 after = [ "hgsrht.service" ];
134 requires = [ "hgsrht.service" ];
136 description = "hg.sr.ht periodic service";
138 serviceConfig.Type = mkForce "oneshot";
139 serviceConfig.Restart = mkForce "no";
140 serviceConfig.ExecStart = "${cfg.python}/bin/hgsrht-periodic";
147 description = "hgsrht periodic timer";
148 wantedBy = [ "timers.target" ];
150 OnCalendar = "20min";
154 hgsrht-clonebundles = {
155 description = "hgsrht daily timer";
156 wantedBy = [ "timers.target" ];
158 OnCalendar = "daily";
165 services.sourcehut.settings = {
166 # The authorized keys hook uses this to dispatch to various handlers
167 # The format is a program to exec into as the key, and the user to match as the
168 # value. When someone tries to log in as this user, this program is executed
169 # and is expected to emit an AuthorizedKeys file.
171 # Uncomment the relevant lines to enable the various sr.ht dispatchers.
172 "hg.sr.ht::dispatch"."/run/current-system/sw/bin/hgsrht-keys" = mkDefault "${user}:${user}";
175 # TODO: requires testing and addition of hg-specific requirements
176 services.nginx.virtualHosts."hg.${cfg.originBase}" = {
178 locations."/".proxyPass = "http://${cfg.address}:${toString port}";
179 locations."/query".proxyPass = cfgIni."meta.sr.ht".api-origin;
180 locations."/static".root = "${pkgs.sourcehut.hgsrht}/${pkgs.sourcehut.python.sitePackages}/hgsrht";