From cc4d8480cf179f22d874d261e9bfa16b02b32445 Mon Sep 17 00:00:00 2001 From: grabowski Date: Tue, 7 Apr 2026 10:13:22 +0700 Subject: [PATCH] Fix flake.nix: node 22, shebang indentation, databaseUrl default, assertion - Upgrade to nodejs_22 (22.22.2) for better Vite 6 compatibility - Fix wrapper script shebang broken by heredoc indentation - Add preBuild step for svelte-kit sync - Default databaseUrl to "" so environmentFile-only configs don't fail eval - Add assertion ensuring either databaseUrl or environmentFile is set Co-Authored-By: Claude Opus 4.6 (1M context) --- flake.nix | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/flake.nix b/flake.nix index 82d2da4..ef95bc6 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,7 @@ flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; - nodejs = pkgs.nodejs_20; + nodejs = pkgs.nodejs_22; in { # Development shell: `nix develop` @@ -38,19 +38,26 @@ src = ./.; - npmDepsHash = ""; # Run `nix build` once to get the correct hash + npmDepsHash = ""; # Run `nix build` once — it will fail and print the correct hash + + nodejs = pkgs.nodejs_22; nativeBuildInputs = [ pkgs.pkg-config - pkgs.python3 # needed by some native modules + pkgs.python3 # needed by sharp native rebuild ]; buildInputs = [ - pkgs.vips # sharp + pkgs.vips pkgs.glib pkgs.expat ]; + # SvelteKit needs sync before build + preBuild = '' + npx svelte-kit sync + ''; + npmBuildScript = "build"; installPhase = '' @@ -62,10 +69,10 @@ cp package.json $out/lib/buildfor_life_repair/ mkdir -p $out/bin - cat > $out/bin/buildfor_life_repair < $out/bin/buildfor_life_repair <<'WRAPPER' +#!/usr/bin/env bash +exec ${pkgs.nodejs_22}/bin/node $out/lib/buildfor_life_repair/index.js "$@" +WRAPPER chmod +x $out/bin/buildfor_life_repair runHook postInstall @@ -102,14 +109,15 @@ databaseUrl = lib.mkOption { type = lib.types.str; - description = "PostgreSQL connection string"; + default = ""; + description = "PostgreSQL connection string. Leave empty if using environmentFile."; example = "postgresql://bflr:password@localhost:5432/buildfor_life_repair"; }; environmentFile = lib.mkOption { type = lib.types.nullOr lib.types.path; default = null; - description = "Path to environment file with secrets (DATABASE_URL, etc). Overrides databaseUrl if set."; + description = "Path to environment file with secrets (DATABASE_URL, etc). Takes precedence over databaseUrl."; }; baseUrl = lib.mkOption { @@ -144,6 +152,13 @@ }; config = lib.mkIf cfg.enable { + assertions = [ + { + assertion = cfg.databaseUrl != "" || cfg.environmentFile != null; + message = "services.buildfor-life-repair: Either databaseUrl or environmentFile must be set."; + } + ]; + users.users.${cfg.user} = { isSystemUser = true; group = cfg.group; @@ -164,7 +179,7 @@ HOST = cfg.host; BASE_URL = cfg.baseUrl; UPLOAD_DIR = cfg.uploadDir; - } // lib.optionalAttrs (cfg.environmentFile == null) { + } // lib.optionalAttrs (cfg.databaseUrl != "") { DATABASE_URL = cfg.databaseUrl; };