This repository has no description
3.6 kB
146 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.termux_massulus.public
74 self.keys.ssh.yubi1.public
75 self.keys.ssh.yubi2.public
76 self.keys.ssh.solo2.public
77 self.keys.ssh.xerxes.public
78 self.keys.ssh.ignavia.public
79 self.keys.ssh.massulus.public
80 ];
81 packages = [
82 pkgs.tmux
83 pkgs.git
84 (pkgs.writeShellScriptBin "kannix-ctl" ''
85 cd ${srcDir}
86 exec "$(nix build .# --no-link --print-out-paths)/bin/kannix-ctl" "$@"
87 '')
88 ];
89 };
90
91 systemd.tmpfiles.rules = [
92 "d ${stateDir}/repos 0755 kannix users -"
93 "d ${stateDir}/worktrees 0755 kannix users -"
94 "d ${stateDir}/checkout 0755 kannix users -"
95 ];
96
97 systemd.services.kannix-checkout = {
98 description = "Create kannix worktree from bare repo";
99 wantedBy = [ "multi-user.target" ];
100 unitConfig.ConditionPathExists = "!${srcDir}/.git";
101 serviceConfig = {
102 Type = "oneshot";
103 User = "kannix";
104 Group = "users";
105 ExecStart = toString (
106 pkgs.writeShellScript "kannix-checkout" ''
107 ${pkgs.git}/bin/git --git-dir=${bareRepo} worktree add ${srcDir} main
108 ''
109 );
110 };
111 };
112
113 systemd.user.services.kannix = {
114 description = "Kannix kanban server";
115 wantedBy = [ "default.target" ];
116 after = [ "network.target" ];
117 path = [
118 pkgs.tmux
119 pkgs.git
120 pkgs.nix
121 ];
122 serviceConfig = {
123 Type = "simple";
124 ExecStart = toString kannixScript;
125 Restart = "on-failure";
126 RestartSec = 5;
127 WorkingDirectory = srcDir;
128 };
129 };
130
131 services.nginx.virtualHosts."kannix.lassul.us" = {
132 enableACME = true;
133 forceSSL = true;
134 locations."/" = {
135 proxyPass = "http://127.0.0.1:${toString port}";
136 proxyWebsockets = true;
137 extraConfig = ''
138 proxy_set_header Host $host;
139 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
140 proxy_set_header X-Forwarded-Proto $scheme;
141 proxy_read_timeout 3600s;
142 proxy_send_timeout 3600s;
143 '';
144 };
145 };
146}