Home

infra @main - refs - log -
-
https://git.jolheiser.com/infra.git
dragonwell flake
tree log patch
prepare git-bug module Signed-off-by: jolheiser <git@jolheiser.com>
Signature
-----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgBTEvCQk6VqUAdN2RuH6bj1dNkY oOpbPWj+jw4ua1B1cAAAADZ2l0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5 AAAAQAbqzzH1SUbYje1AfaPpusrb5m8vozW6A/2FlCillL5Eyhd8kLxCqh3IUUa9DydkCF tfj7SVAYEfLNSLJhkVCwY= -----END SSH SIGNATURE-----
jolheiser <git@jolheiser.com>
1 week ago
4 changed files, 207 additions(+), 0 deletions(-)
dragonwell/default.nixdragonwell/git-bug.nixflake.nixmodules/git-bug/default.nix
M dragonwell/default.nixdragonwell/default.nix
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
diff --git a/dragonwell/default.nix b/dragonwell/default.nix
index 37808569685697d5da8320201b5a626887196dfe..71582f32bd75937489e57554a560a6b7f541d4ad 100644
--- a/dragonwell/default.nix
+++ b/dragonwell/default.nix
@@ -8,6 +8,7 @@     ./beszel.nix
     ./caddy.nix
     ./forge-lines.nix
     ./foundry.nix
+    ./git-bug.nix
     ./git-pr.nix
     ./mealie.nix
     ./miniserve.nix
I dragonwell/git-bug.nix
 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
diff --git a/dragonwell/git-bug.nix b/dragonwell/git-bug.nix
new file mode 100644
index 0000000000000000000000000000000000000000..c7bfe2ae4a07f506a4365622912a742f7b52a215
--- /dev/null
+++ b/dragonwell/git-bug.nix
@@ -0,0 +1,19 @@
+{
+  services = {
+    git-bug.bugs = {
+      enable = false;
+      repoDir = "/var/lib/ugit/repos/bugs.git";
+      authorUser = "jolheiser";
+      authorEmail = "bugs@jolheiser.com";
+      authorAvatar = "https://www.libravatar.org/avatar/cc498b605dee7b6fb9e6422332691bb4";
+      host = "localhost";
+      port = 2847;
+    };
+    tailproxy.bugs = {
+      enable = false;
+      hostname = "bugs";
+      port = 2847;
+      authKey = ""; # One-time key
+    };
+  };
+}
M flake.nixflake.nix
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
diff --git a/flake.nix b/flake.nix
index 942d80cc13fc5528317a4a77eb922b0f9bab1c1b..5ba42f793b694fa11144034a0e9e909932ed0adc 100644
--- a/flake.nix
+++ b/flake.nix
@@ -75,6 +75,7 @@           inputs.tailproxy.nixosModules.default
           inputs.foundry.nixosModules.foundryvtt
           inputs.forge-lines.nixosModules.default
           ./modules/miniserve
+          ./modules/git-bug
           ./dragonwell
           beszelAgent
         ];
I modules/git-bug/default.nix
  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
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
diff --git a/modules/git-bug/default.nix b/modules/git-bug/default.nix
new file mode 100644
index 0000000000000000000000000000000000000000..5a488a34c73b3ee54857e9ef247f1979ad36a0ee
--- /dev/null
+++ b/modules/git-bug/default.nix
@@ -0,0 +1,186 @@
+{
+  pkgs,
+  config,
+  lib,
+  ...
+}:
+let
+  cfg = config.services.git-bug;
+  pkg = pkgs.git-bug;
+  instanceOptions =
+    { name, config, ... }:
+    let
+      inherit (lib) mkEnableOption mkOption types;
+    in
+    {
+      enable = mkEnableOption "Enable git-bug web UI";
+
+      package = mkOption {
+        type = types.package;
+        description = "git-bug package to use";
+        default = pkg;
+      };
+
+      repoDir = mkOption {
+        type = types.str;
+        description = "git repo for bugs";
+      };
+
+      authorUser = mkOption {
+        type = types.str;
+        description = "git-bug user to use";
+        default = "git-bug";
+      };
+
+      authorEmail = mkOption {
+        type = types.str;
+        description = "git-bug user email to use";
+        default = "bugs@example.com";
+      };
+
+      authorAvatar = mkOption {
+        type = types.str;
+        description = "git-bug user avatar to use";
+        default = "";
+      };
+
+      host = mkOption {
+        type = types.str;
+        description = "Network address or hostname to listen to";
+        default = "127.0.0.1";
+      };
+
+      port = mkOption {
+        type = types.port;
+        description = "Port to listen to (default to random available port)";
+        default = 0;
+      };
+
+      readOnly = mkOption {
+        type = types.bool;
+        description = "Whether to run the web UI in read-only mode";
+        default = false;
+      };
+
+      logErrors = mkOption {
+        type = types.bool;
+        description = "Whether to log errors";
+        default = false;
+      };
+
+      query = mkOption {
+        type = types.str;
+        description = "The query to open in the web UI bug list";
+        default = "";
+      };
+
+      user = mkOption {
+        type = types.str;
+        description = "user account under which git-bug runs";
+        default = "git-bug-${name}";
+      };
+
+      group = mkOption {
+        type = types.str;
+        description = "Group account under which git-bug runs";
+        default = "git-bug-${name}";
+      };
+    };
+in
+{
+  options.services.git-bug = lib.mkOption {
+    type = lib.types.attrsOf (lib.types.submodule instanceOptions);
+    description = "Attribute set of git-bug instances";
+    default = { };
+  };
+  config = lib.mkIf (cfg != { }) {
+    users.users = lib.mapAttrs' (
+      name: instanceCfg:
+      lib.nameValuePair instanceCfg.user {
+        home = instanceCfg.repoDir;
+        group = instanceCfg.group;
+        isSystemUser = true;
+        isNormalUser = false;
+        description = "user for git-bug ${name} service";
+      }
+    ) (lib.filterAttrs (name: instanceCfg: instanceCfg.enable) cfg);
+
+    users.groups = lib.mapAttrs' (name: instanceCfg: lib.nameValuePair instanceCfg.group { }) (
+      lib.filterAttrs (name: instanceCfg: instanceCfg.enable) cfg
+    );
+
+    systemd.services = lib.foldl' (
+      acc: name:
+      let
+        instanceCfg = cfg.${name};
+      in
+      lib.recursiveUpdate acc (
+        lib.optionalAttrs instanceCfg.enable {
+          "git-bug-${name}" = {
+            enable = true;
+            description = "git-bug instance ${name}";
+            wantedBy = [ "multi-user.target" ];
+            after = [ "network.target" ];
+            path = [ instanceCfg.package ];
+            serviceConfig = {
+              User = instanceCfg.user;
+              Group = instanceCfg.group;
+              Restart = "always";
+              RestartSec = "15";
+              WorkingDirectory = instanceCfg.repoDir;
+              ReadWritePaths = [ instanceCfg.repoDir ];
+              CapabilityBoundingSet = "";
+              NoNewPrivileges = true;
+              ProtectSystem = "strict";
+              ProtectHome = true;
+              PrivateTmp = true;
+              PrivateDevices = true;
+              PrivateUsers = true;
+              ProtectHostname = true;
+              ProtectClock = true;
+              ProtectKernelTunables = true;
+              ProtectKernelModules = true;
+              ProtectKernelLogs = true;
+              ProtectControlGroups = true;
+              RestrictAddressFamilies = [
+                "AF_UNIX"
+                "AF_INET"
+                "AF_INET6"
+              ];
+              RestrictNamespaces = true;
+              LockPersonality = true;
+              MemoryDenyWriteExecute = true;
+              RestrictRealtime = true;
+              RestrictSUIDSGID = true;
+              RemoveIPC = true;
+              PrivateMounts = true;
+              SystemCallArchitectures = "native";
+              ExecStart =
+                let
+                  args = [
+                    "--host=${instanceCfg.host}"
+                    "--no-open"
+                    "--port=${builtins.toString instanceCfg.port}"
+                    (lib.optionalString instanceCfg.readOnly "--read-only")
+                    (lib.optionalString instanceCfg.logErrors "--log-errors")
+                    "--query=${instanceCfg.query}"
+                  ];
+                in
+                "${lib.getExe instanceCfg.package} ${builtins.concatStringsSep " " args}";
+              ExecStartPre = pkgs.writeShellScript "git-bug-${name}-author" ''
+                human_id=$(git-bug user --format json | jq -r '.[] | select(.name == "${instanceCfg.authorUser}") | .human_id' 2>/dev/null || echo "")
+                if [ -n "$human_id" ] && [ "$human_id" != "null" ]; then
+                    git-bug user adopt "$human_id"
+                else
+                    git-bug user new --name "${instanceCfg.authorUser}" --email "${instanceCfg.authorUser}" ${
+                      lib.optionalString (instanceCfg != "") "--avatar \"${instanceCfg.authorAvatar}\""
+                    }
+                fi
+              '';
+            };
+          };
+        }
+      )
+    );
+  };
+}