This repository has no description
3.6 kB
145 lines
1{
2 self,
3 pkgs,
4 lib,
5 ...
6}:
7let
8 port = 4243;
9 stateDir = "/var/lib/kannix";
10 bareRepo = "${stateDir}/repos/kannix.git";
11 srcDir = "${stateDir}/checkout/kannix";
12
13 configFile = pkgs.writeText "kannix.json" (
14 builtins.toJSON {
15 columns = [
16 "backlog"
17 "planning"
18 "doing"
19 "review"
20 "done"
21 ];
22 server = {
23 host = "127.0.0.1";
24 inherit port;
25 };
26 repos_dir = "${stateDir}/repos";
27 worktree_dir = "${stateDir}/worktrees";
28 }
29 );
30
31 kannixScript = pkgs.writeShellScript "kannix-run" ''
32 export KANNIX_CONFIG=${configFile}
33 export KANNIX_STATE_DIR=${stateDir}
34 export PATH=${
35 lib.makeBinPath [
36 pkgs.tmux
37 pkgs.git
38 pkgs.nix
39 pkgs.inotify-tools
40 pkgs.coreutils
41 ]
42 }:$PATH
43 cd ${srcDir}
44
45 while true; do
46 nix run .# -- \
47 --host 127.0.0.1 \
48 --port ${toString port} &
49 PID=$!
50
51 inotifywait -r -e modify,create,delete,move \
52 --exclude '(__pycache__|\.pyc|\.git/|result)' \
53 ${srcDir}/src ${srcDir}/flake.nix ${srcDir}/flake.lock ${srcDir}/package.nix ${srcDir}/pyproject.toml
54
55 echo "Change detected, restarting..."
56 kill $PID 2>/dev/null
57 wait $PID 2>/dev/null
58 sleep 1
59 done
60 '';
61in
62{
63 users.users.kannix = {
64 isNormalUser = true;
65 home = stateDir;
66 createHome = true;
67 group = "users";
68 shell = pkgs.bashInteractive;
69 linger = true;
70 openssh.authorizedKeys.keys = [
71 self.keys.ssh.barnacle.public
72 self.keys.ssh.yubi_pgp.public
73 self.keys.ssh.yubi1.public
74 self.keys.ssh.yubi2.public
75 self.keys.ssh.solo2.public
76 self.keys.ssh.xerxes.public
77 self.keys.ssh.ignavia.public
78 self.keys.ssh.massulus.public
79 ];
80 packages = [
81 pkgs.tmux
82 pkgs.git
83 (pkgs.writeShellScriptBin "kannix-ctl" ''
84 cd ${srcDir}
85 exec "$(nix build .# --no-link --print-out-paths)/bin/kannix-ctl" "$@"
86 '')
87 ];
88 };
89
90 systemd.tmpfiles.rules = [
91 "d ${stateDir}/repos 0755 kannix users -"
92 "d ${stateDir}/worktrees 0755 kannix users -"
93 "d ${stateDir}/checkout 0755 kannix users -"
94 ];
95
96 systemd.services.kannix-checkout = {
97 description = "Create kannix worktree from bare repo";
98 wantedBy = [ "multi-user.target" ];
99 unitConfig.ConditionPathExists = "!${srcDir}/.git";
100 serviceConfig = {
101 Type = "oneshot";
102 User = "kannix";
103 Group = "users";
104 ExecStart = toString (
105 pkgs.writeShellScript "kannix-checkout" ''
106 ${pkgs.git}/bin/git --git-dir=${bareRepo} worktree add ${srcDir} main
107 ''
108 );
109 };
110 };
111
112 systemd.user.services.kannix = {
113 description = "Kannix kanban server";
114 wantedBy = [ "default.target" ];
115 after = [ "network.target" ];
116 path = [
117 pkgs.tmux
118 pkgs.git
119 pkgs.nix
120 ];
121 serviceConfig = {
122 Type = "simple";
123 ExecStart = toString kannixScript;
124 Restart = "on-failure";
125 RestartSec = 5;
126 WorkingDirectory = srcDir;
127 };
128 };
129
130 services.nginx.virtualHosts."kannix.lassul.us" = {
131 enableACME = true;
132 forceSSL = true;
133 locations."/" = {
134 proxyPass = "http://127.0.0.1:${toString port}";
135 proxyWebsockets = true;
136 extraConfig = ''
137 proxy_set_header Host $host;
138 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
139 proxy_set_header X-Forwarded-Proto $scheme;
140 proxy_read_timeout 3600s;
141 proxy_send_timeout 3600s;
142 '';
143 };
144 };
145}