]> Git — Sourcephile - sourcephile-nix.git/blob - nixos/modules/services/misc/sourcehut/hub.nix
losurdo: sourcehut: sync config with module changes
[sourcephile-nix.git] / nixos / modules / services / misc / sourcehut / hub.nix
1 { config, lib, pkgs, ... }:
2
3 with lib;
4 let
5 cfg = config.services.sourcehut;
6 cfgIni = cfg.settings;
7 scfg = cfg.hub;
8 iniKey = "hub.sr.ht";
9 statePath = "/var/lib/sourcehut/hubsrht";
10
11 drv = pkgs.sourcehut.hubsrht;
12 in
13 {
14 options.services.sourcehut.hub = {
15 enable = mkEnableOption "hub service";
16
17 user = mkOption {
18 type = types.str;
19 default = "hubsrht";
20 description = ''
21 User for hub.sr.ht.
22 '';
23 };
24
25 port = mkOption {
26 type = types.port;
27 default = 5014;
28 description = ''
29 Port on which the "hub" module should listen.
30 '';
31 };
32
33 database = mkOption {
34 type = types.str;
35 default = "hub.sr.ht";
36 description = ''
37 PostgreSQL database name for hub.sr.ht.
38 '';
39 };
40 };
41
42 config = with scfg; lib.mkIf (cfg.enable && scfg.enable) {
43 users = {
44 users = {
45 "${user}" = {
46 isSystemUser = true;
47 group = user;
48 description = "hub.sr.ht user";
49 };
50 };
51
52 groups = {
53 "${user}" = { };
54 };
55 };
56
57 services.postgresql = {
58 authentication = ''
59 local ${database} ${user} trust
60 '';
61 ensureDatabases = [ database ];
62 ensureUsers = [
63 {
64 name = user;
65 ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
66 }
67 ];
68 };
69
70 systemd = {
71 services.hubsrht = import ./service.nix { inherit config pkgs lib; initDB = true; } scfg drv iniKey {
72 after = [ "postgresql.service" "network.target" ];
73 requires = [ "postgresql.service" ];
74 wantedBy = [ "multi-user.target" ];
75
76 description = "hub.sr.ht website service";
77
78 serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
79 };
80 };
81
82 services.nginx.virtualHosts."${cfg.originBase}" = {
83 forceSSL = true;
84 locations."/".proxyPass = "http://${cfg.address}:${toString port}";
85 locations."/query".proxyPass = cfgIni."meta.sr.ht".api-origin;
86 locations."/static".root = "${pkgs.sourcehut.hubsrht}/${pkgs.sourcehut.python.sitePackages}/hubsrht";
87 };
88 services.nginx.virtualHosts."hub.${cfg.originBase}" = {
89 globalRedirect = "${cfg.originBase}";
90 forceSSL = true;
91 };
92 };
93 }