Home

infra @753a787c2b0026e34e4c25fb6b5d93e1368ee226 - refs - log -
-
https://git.jolheiser.com/infra.git
dragonwell flake
infra / dragonwell / gollum.nix
- raw -
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{ pkgs, config, ... }:
{
  services = {
    gollum = {
      enable = true;
      stateDir = "/var/lib/ugit/repos/wiki.git";
      emoji = true;
      h1-title = true;
      port = 9454;
      branch = "main";
      user = "ugit";
      group = "ugit";
    };
    caddy.virtualHosts."wiki.jolheiser.com".extraConfig = ''
      	handle /oauth2/* {
      		reverse_proxy localhost:6227 {
      			header_up X-Real-IP {remote_host}
      			header_up X-Forwarded-Uri {uri}
      		}
      	}

      	handle {
      		forward_auth localhost:6227 {
      			uri /oauth2/auth

      			header_up X-Real-IP {remote_host}

      			@error status 401
      			handle_response @error {
      				redir * /oauth2/sign_in?rd={scheme}://{host}{uri}
      			}
      		}

      		reverse_proxy localhost:9454
      	}
    '';
  };

  # Hack to work with bare repos
  systemd.services.gollum =
    let
      cfg = config.services.gollum;
    in
    {
      preStart = pkgs.lib.mkForce ''
        git init --bare ${cfg.stateDir}
      '';
      serviceConfig.ExecStart = pkgs.lib.mkForce ''
        ${cfg.package}/bin/gollum \
              --port ${toString cfg.port} \
              --host ${cfg.address} \
              --config ${pkgs.writeText "gollum-config.rb" cfg.extraConfig} \
              --ref ${cfg.branch} \
              ${pkgs.lib.optionalString cfg.math "--math"} \
              ${pkgs.lib.optionalString cfg.emoji "--emoji"} \
              ${pkgs.lib.optionalString cfg.h1-title "--h1-title"} \
              ${pkgs.lib.optionalString cfg.no-edit "--no-edit"} \
              ${pkgs.lib.optionalString (cfg.allowUploads != null) "--allow-uploads ${cfg.allowUploads}"} \
              ${pkgs.lib.optionalString (cfg.user-icons != null) "--user-icons ${cfg.user-icons}"} \
              --bare \
              --css \
              --js \
              ${cfg.stateDir}
      '';
    };
}