From d7ff9947e53746f6a3173f42684b0a3192fb1785 Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 19 Apr 2026 06:22:23 +0700 Subject: [PATCH 01/19] m --- .woodpecker.yml | 26 ++++++++++++++++++++++++++ .woodpecker/wtfisthis | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 .woodpecker.yml create mode 100644 .woodpecker/wtfisthis diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..f36f21a --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,26 @@ +steps: + checks: + image: nixos/nix:latest + commands: + - nix develop --accept-flake-config -c bun install --frozen-lockfile + - nix develop --accept-flake-config -c bun run lint + - nix develop --accept-flake-config -c bun run typecheck + - nix develop --accept-flake-config -c bun run build + - nix develop --accept-flake-config -c bun run update:bun-nix + - git diff --exit-code bun.nix + - nix build --accept-flake-config .#default + +when: + - event: [pull_request, push] + +--- + +steps: + deploy: + image: nixos/nix:latest + commands: + - sudo -n /usr/local/libexec/deploy-sortug + +when: + - event: push + - branch: master diff --git a/.woodpecker/wtfisthis b/.woodpecker/wtfisthis new file mode 100644 index 0000000..f36f21a --- /dev/null +++ b/.woodpecker/wtfisthis @@ -0,0 +1,26 @@ +steps: + checks: + image: nixos/nix:latest + commands: + - nix develop --accept-flake-config -c bun install --frozen-lockfile + - nix develop --accept-flake-config -c bun run lint + - nix develop --accept-flake-config -c bun run typecheck + - nix develop --accept-flake-config -c bun run build + - nix develop --accept-flake-config -c bun run update:bun-nix + - git diff --exit-code bun.nix + - nix build --accept-flake-config .#default + +when: + - event: [pull_request, push] + +--- + +steps: + deploy: + image: nixos/nix:latest + commands: + - sudo -n /usr/local/libexec/deploy-sortug + +when: + - event: push + - branch: master From 2a8804ca02b9ed15c2bf23f71a0b5123cd8d826a Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 19 Apr 2026 06:23:17 +0700 Subject: [PATCH 02/19] m --- .woodpecker.yml => .woodpecker/wtf | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .woodpecker.yml => .woodpecker/wtf (100%) diff --git a/.woodpecker.yml b/.woodpecker/wtf similarity index 100% rename from .woodpecker.yml rename to .woodpecker/wtf From 7df70294d380ef6fc2015ddd3351dd67d3007488 Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 19 Apr 2026 06:34:39 +0700 Subject: [PATCH 03/19] m --- .woodpecker/job.yaml | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/.woodpecker/job.yaml b/.woodpecker/job.yaml index c0ffef9..acacdd5 100644 --- a/.woodpecker/job.yaml +++ b/.woodpecker/job.yaml @@ -1,9 +1,27 @@ - when: - - event: push - - branch: master +when: + - event: push - steps: - deploy: - commands: - - sh ~/nixconf/update.sh - - nh os switch -H sortug ~/nixconf --target-host root@sortug +steps: + - name: smoke + image: bash + commands: + - pwd + - whoami + - hostname + - git rev-parse --short HEAD + - test -d ~/nixconf + - printf '%s %s %s\n' "$(date --iso-8601=seconds)" "$(hostname)" "$(git rev-parse --short HEAD)" >> ~/woodpecker-smoke.log + - tail -n 5 ~/woodpecker-smoke.log + +--- + +when: + - event: push + - branch: master + +steps: + - name: deploy + image: bash + commands: + - sh ~/nixconf/update.sh + - nh os switch -H sortug ~/nixconf --target-host root@sortug From cc5c91a9b6ee066901ed614b4befe56377a0a175 Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 19 Apr 2026 06:49:47 +0700 Subject: [PATCH 04/19] m --- .woodpecker/job.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.woodpecker/job.yaml b/.woodpecker/job.yaml index acacdd5..50f0e7c 100644 --- a/.woodpecker/job.yaml +++ b/.woodpecker/job.yaml @@ -8,7 +8,7 @@ steps: - pwd - whoami - hostname - - git rev-parse --short HEAD + # - git rev-parse --short HEAD - test -d ~/nixconf - printf '%s %s %s\n' "$(date --iso-8601=seconds)" "$(hostname)" "$(git rev-parse --short HEAD)" >> ~/woodpecker-smoke.log - tail -n 5 ~/woodpecker-smoke.log @@ -24,4 +24,5 @@ steps: image: bash commands: - sh ~/nixconf/update.sh - - nh os switch -H sortug ~/nixconf --target-host root@sortug + # - nh os switch -H sortug ~/nixconf --target-host root@sortug + - nixos-rebuild switch --flake ~/nixconf#sortug --target-host root@sortug From 03e967124a4f749edba093e1bc49e5742b52f7a0 Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 19 Apr 2026 06:58:54 +0700 Subject: [PATCH 05/19] m --- lol.lmao | 1 + 1 file changed, 1 insertion(+) create mode 100644 lol.lmao diff --git a/lol.lmao b/lol.lmao new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/lol.lmao @@ -0,0 +1 @@ +1 From db90cac05a576237094d8fd0e482b07e7834c92f Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 19 Apr 2026 07:05:14 +0700 Subject: [PATCH 06/19] m --- lol.lmao | 1 + 1 file changed, 1 insertion(+) diff --git a/lol.lmao b/lol.lmao index d00491f..1191247 100644 --- a/lol.lmao +++ b/lol.lmao @@ -1 +1,2 @@ 1 +2 From 4a210f07624ad9b59586b9a0d828b71fca546f13 Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 19 Apr 2026 07:08:59 +0700 Subject: [PATCH 07/19] m --- lol.lmao | 1 + 1 file changed, 1 insertion(+) diff --git a/lol.lmao b/lol.lmao index 1191247..01e79c3 100644 --- a/lol.lmao +++ b/lol.lmao @@ -1,2 +1,3 @@ 1 2 +3 From bd15dc34337d01ed04901c2102837e2672b81fc1 Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 19 Apr 2026 07:56:54 +0700 Subject: [PATCH 08/19] m --- .woodpecker/job.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.woodpecker/job.yaml b/.woodpecker/job.yaml index 50f0e7c..caf1caf 100644 --- a/.woodpecker/job.yaml +++ b/.woodpecker/job.yaml @@ -8,8 +8,6 @@ steps: - pwd - whoami - hostname - # - git rev-parse --short HEAD - - test -d ~/nixconf - printf '%s %s %s\n' "$(date --iso-8601=seconds)" "$(hostname)" "$(git rev-parse --short HEAD)" >> ~/woodpecker-smoke.log - tail -n 5 ~/woodpecker-smoke.log @@ -23,6 +21,4 @@ steps: - name: deploy image: bash commands: - - sh ~/nixconf/update.sh - # - nh os switch -H sortug ~/nixconf --target-host root@sortug - - nixos-rebuild switch --flake ~/nixconf#sortug --target-host root@sortug + - sudo -n /usr/local/libexec/deploy-kotsukotsu From e8c14e7447161499117afa6412643a825cbd63be Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 19 Apr 2026 08:00:53 +0700 Subject: [PATCH 09/19] m --- .woodpecker/job.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.woodpecker/job.yaml b/.woodpecker/job.yaml index caf1caf..00e0f52 100644 --- a/.woodpecker/job.yaml +++ b/.woodpecker/job.yaml @@ -8,8 +8,8 @@ steps: - pwd - whoami - hostname - - printf '%s %s %s\n' "$(date --iso-8601=seconds)" "$(hostname)" "$(git rev-parse --short HEAD)" >> ~/woodpecker-smoke.log - - tail -n 5 ~/woodpecker-smoke.log + - printf '%s %s %s\n' "$(date --iso-8601=seconds)" "$(hostname)" "$(git rev-parse --short HEAD)" >> /var/tmp/woodpecker-smoke.log + - tail -n 5 /var/tmp/woodpecker-smoke.log --- From 2106be1b57db63da1458f1d172204e3c5c4d3f0c Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 19 Apr 2026 08:05:33 +0700 Subject: [PATCH 10/19] m --- .woodpecker/job.yaml | 8 +------- lol.lmao | 1 + 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.woodpecker/job.yaml b/.woodpecker/job.yaml index 00e0f52..b448d8b 100644 --- a/.woodpecker/job.yaml +++ b/.woodpecker/job.yaml @@ -11,14 +11,8 @@ steps: - printf '%s %s %s\n' "$(date --iso-8601=seconds)" "$(hostname)" "$(git rev-parse --short HEAD)" >> /var/tmp/woodpecker-smoke.log - tail -n 5 /var/tmp/woodpecker-smoke.log ---- - -when: - - event: push - - branch: master - -steps: - name: deploy image: bash commands: + - '[ "${CI_COMMIT_BRANCH:-}" = "master" ] || { echo "skipping deploy on branch ${CI_COMMIT_BRANCH:-unknown}"; exit 0; }' - sudo -n /usr/local/libexec/deploy-kotsukotsu diff --git a/lol.lmao b/lol.lmao index 01e79c3..94ebaf9 100644 --- a/lol.lmao +++ b/lol.lmao @@ -1,3 +1,4 @@ 1 2 3 +4 From 3a9e6eed7f8cd16b01ee953ab5e247dd51085780 Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 19 Apr 2026 08:08:36 +0700 Subject: [PATCH 11/19] 1 --- .woodpecker/job.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.woodpecker/job.yaml b/.woodpecker/job.yaml index b448d8b..b718713 100644 --- a/.woodpecker/job.yaml +++ b/.woodpecker/job.yaml @@ -15,4 +15,4 @@ steps: image: bash commands: - '[ "${CI_COMMIT_BRANCH:-}" = "master" ] || { echo "skipping deploy on branch ${CI_COMMIT_BRANCH:-unknown}"; exit 0; }' - - sudo -n /usr/local/libexec/deploy-kotsukotsu + - /run/wrappers/bin/sudo -n /usr/local/libexec/deploy-kotsukotsu From dc28c16a328a90199c9ff41f2f96ba1dba6ec92e Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 19 Apr 2026 08:13:57 +0700 Subject: [PATCH 12/19] 1 --- .woodpecker/job.yaml | 2 +- lol.lmao | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.woodpecker/job.yaml b/.woodpecker/job.yaml index b718713..d934026 100644 --- a/.woodpecker/job.yaml +++ b/.woodpecker/job.yaml @@ -15,4 +15,4 @@ steps: image: bash commands: - '[ "${CI_COMMIT_BRANCH:-}" = "master" ] || { echo "skipping deploy on branch ${CI_COMMIT_BRANCH:-unknown}"; exit 0; }' - - /run/wrappers/bin/sudo -n /usr/local/libexec/deploy-kotsukotsu + - /usr/local/libexec/deploy-kotsukotsu diff --git a/lol.lmao b/lol.lmao index 94ebaf9..8a1218a 100644 --- a/lol.lmao +++ b/lol.lmao @@ -2,3 +2,4 @@ 2 3 4 +5 From 6b623a07341878c7fc6ac3885d345483d3a21991 Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 19 Apr 2026 08:19:15 +0700 Subject: [PATCH 13/19] m1 --- lol.lmao | 1 + 1 file changed, 1 insertion(+) diff --git a/lol.lmao b/lol.lmao index 8a1218a..b414108 100644 --- a/lol.lmao +++ b/lol.lmao @@ -3,3 +3,4 @@ 3 4 5 +6 From 36613e377aba0cd127ac344c3e0bf3dffd74bf49 Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 19 Apr 2026 08:21:37 +0700 Subject: [PATCH 14/19] m2 --- lol.lmao | 1 + 1 file changed, 1 insertion(+) diff --git a/lol.lmao b/lol.lmao index b414108..06e567b 100644 --- a/lol.lmao +++ b/lol.lmao @@ -4,3 +4,4 @@ 4 5 6 +7 From c38811e3a0c66207a902c96335a603d9d9f5f13f Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 19 Apr 2026 08:29:19 +0700 Subject: [PATCH 15/19] 1 --- lol.lmao | 1 + 1 file changed, 1 insertion(+) diff --git a/lol.lmao b/lol.lmao index 06e567b..535d2b0 100644 --- a/lol.lmao +++ b/lol.lmao @@ -5,3 +5,4 @@ 5 6 7 +8 From 3a007a9b1dcac801b4f6512c11936de5f888781e Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 19 Apr 2026 08:39:59 +0700 Subject: [PATCH 16/19] 1 --- lol.lmao | 1 + 1 file changed, 1 insertion(+) diff --git a/lol.lmao b/lol.lmao index 535d2b0..0719398 100644 --- a/lol.lmao +++ b/lol.lmao @@ -6,3 +6,4 @@ 6 7 8 +9 From 0790da4e32535ec81de2c00f8ff36fbb0c1061b6 Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 19 Apr 2026 08:40:52 +0700 Subject: [PATCH 17/19] 1 --- lol.lmao | 1 + 1 file changed, 1 insertion(+) diff --git a/lol.lmao b/lol.lmao index 0719398..f00c965 100644 --- a/lol.lmao +++ b/lol.lmao @@ -7,3 +7,4 @@ 7 8 9 +10 From 78cc1b95bbb1fdf7c7102cca660d7d7e0e8891d3 Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 19 Apr 2026 08:51:24 +0700 Subject: [PATCH 18/19] surrender --- .woodpecker/job.yaml | 2 +- nix/module.nix | 21 ++++++++++++++++++++- scripts/deploy-app.sh | 28 ++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 scripts/deploy-app.sh diff --git a/.woodpecker/job.yaml b/.woodpecker/job.yaml index d934026..b9c484a 100644 --- a/.woodpecker/job.yaml +++ b/.woodpecker/job.yaml @@ -15,4 +15,4 @@ steps: image: bash commands: - '[ "${CI_COMMIT_BRANCH:-}" = "master" ] || { echo "skipping deploy on branch ${CI_COMMIT_BRANCH:-unknown}"; exit 0; }' - - /usr/local/libexec/deploy-kotsukotsu + - bash ./scripts/deploy-app.sh diff --git a/nix/module.nix b/nix/module.nix index 90e2bb1..82bcdee 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -2,6 +2,14 @@ let cfg = config.services.kotsukotsu; + launcher = pkgs.writeShellScript "kotsukotsu-launch" '' + exec ${cfg.currentPath}/bin/kotsukotsu + ''; + ensureCurrent = pkgs.writeShellScript "kotsukotsu-ensure-current" '' + if [ ! -e ${cfg.currentPath} ]; then + ln -sfn ${cfg.package} ${cfg.currentPath} + fi + ''; in { options.services.kotsukotsu = { @@ -38,6 +46,12 @@ in description = "Directory for the persistent SQLite database."; }; + currentPath = lib.mkOption { + type = lib.types.str; + default = "/var/lib/kotsukotsu/current"; + description = "Stable symlink path that points at the active app package."; + }; + user = lib.mkOption { type = lib.types.str; default = "kotsukotsu"; @@ -71,6 +85,10 @@ in assertion = lib.hasPrefix "/" cfg.dataDir; message = "services.kotsukotsu.dataDir must be an absolute path."; } + { + assertion = lib.hasPrefix "/" cfg.currentPath; + message = "services.kotsukotsu.currentPath must be an absolute path."; + } ]; users.groups = lib.mkIf (cfg.group == "kotsukotsu") { @@ -104,7 +122,8 @@ in }; serviceConfig = { - ExecStart = lib.getExe cfg.package; + ExecStart = launcher; + ExecStartPre = ensureCurrent; Group = cfg.group; Restart = "on-failure"; User = cfg.user; diff --git a/scripts/deploy-app.sh b/scripts/deploy-app.sh new file mode 100644 index 0000000..eae4f9c --- /dev/null +++ b/scripts/deploy-app.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -euo pipefail + +target_host="${1:-root@sortug.com}" +service_name="${SERVICE_NAME:-kotsukotsu}" +current_path="${CURRENT_PATH:-/var/lib/kotsukotsu/current}" +health_url="${HEALTH_URL:-http://127.0.0.1:5174/healthz}" + +store_path="$(nix build --accept-flake-config --print-out-paths .#default | tail -n 1)" + +echo "Built ${store_path}" +echo "Copying package to ${target_host}" +nix copy --to "ssh://${target_host}" "${store_path}" + +echo "Activating release on ${target_host}" +ssh "${target_host}" " + set -euo pipefail + ln -sfn '${store_path}' '${current_path}' + systemctl restart '${service_name}' + for _ in 1 2 3 4 5 6 7 8 9 10; do + if curl -fsS '${health_url}' >/dev/null; then + exit 0 + fi + sleep 1 + done + echo 'health check failed for ${service_name}' >&2 + exit 1 +" From bd24e3a5f78fb4df0007ffef1930d91522ffb5e9 Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 19 Apr 2026 08:53:18 +0700 Subject: [PATCH 19/19] 1 --- lol.lmao | 1 + 1 file changed, 1 insertion(+) diff --git a/lol.lmao b/lol.lmao index f00c965..3bb459b 100644 --- a/lol.lmao +++ b/lol.lmao @@ -8,3 +8,4 @@ 8 9 10 +11