From 37979340d9a950d0c82a27897fba1069ad5dec83 Mon Sep 17 00:00:00 2001 From: TheGeneralist <180094941+thegeneralist01@users.noreply.github.com> Date: Tue, 17 Feb 2026 07:49:12 +0100 Subject: [PATCH] fix calorie-tracker service prestart and build flow Run prestart from the state directory, normalize write permissions after rsync, install required dev dependencies for Astro build checks, and force clean dist rebuilds to prevent stale artifact module errors. --- flake.lock | 8 ++++---- .../calorie-tracker/default.nix | 14 ++++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/flake.lock b/flake.lock index 7de845f..1c41f87 100644 --- a/flake.lock +++ b/flake.lock @@ -50,11 +50,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1771307893, - "narHash": "sha256-wHBIQSFjo/KWcY9Xvq30wsVAaNGEgirwebFQjqujPiU=", + "lastModified": 1771309191, + "narHash": "sha256-Y83E1JrimzUPQ1a7FpOd9dIQFJFucbV4lYPI7ik3Piw=", "ref": "refs/heads/master", - "rev": "977eeccd7f2702ae85ff562b4f8bd39c3cbb1898", - "revCount": 1, + "rev": "8cf458087edb5f2ff7e3563d4bb6e489c3264d1d", + "revCount": 2, "type": "git", "url": "file:///home/thegeneralist/calorie-tracker" }, diff --git a/hosts/thegeneralist-central/calorie-tracker/default.nix b/hosts/thegeneralist-central/calorie-tracker/default.nix index 3868f03..9864eb2 100644 --- a/hosts/thegeneralist-central/calorie-tracker/default.nix +++ b/hosts/thegeneralist-central/calorie-tracker/default.nix @@ -48,6 +48,7 @@ in preStart = '' mkdir -p ${appDir} rsync -a --delete --exclude ".git" --exclude "node_modules" --exclude "dist" --exclude ".astro" ${sourceDir}/ ${appDir}/ + chmod -R u+rwX ${appDir} cd ${appDir} @@ -57,16 +58,15 @@ in sed -i 's#^DATABASE_URL=.*#DATABASE_URL="file:${dataDir}/dev.db"#' .env - if [ ! -d node_modules ] || [ ! -d node_modules/@astrojs/node ] || [ ! -d node_modules/server-destroy ]; then - npm ci --no-fund --no-audit + if [ ! -d node_modules ] || [ ! -d node_modules/@astrojs/node ] || [ ! -d node_modules/server-destroy ] || [ ! -d node_modules/@vite-pwa/astro ] || [ ! -d node_modules/@astrojs/check ]; then + npm ci --include=dev --no-fund --no-audit fi sqlite3 "${dataDir}/dev.db" < ${./schema.sql} npm run prisma:generate - if [ ! -f dist/server/entry.mjs ]; then - npm run build - fi + rm -rf dist + npm run build ''; serviceConfig = { @@ -75,7 +75,9 @@ in Group = "users"; StateDirectory = "calorie-tracker"; StateDirectoryMode = "0750"; - WorkingDirectory = appDir; + # Keep working dir on the guaranteed StateDirectory path so preStart can + # create ${appDir} on first boot/deploy before ExecStart runs. + WorkingDirectory = dataDir; ExecStart = "${pkgs.nodejs_22}/bin/node ${appDir}/dist/server/entry.mjs"; KillMode = "mixed"; Restart = "always";