From f2967616d3c8b0ca3854e1294a5d45499e147142 Mon Sep 17 00:00:00 2001 From: Padreug Date: Wed, 10 Jun 2026 16:42:57 +0200 Subject: [PATCH] feat(nix): lib.mkWebapp accepts extraEnv for build-time VITE_* vars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NixOS consumers (webapp-module's hub build, server-deploy's standalones module) bake VITE_* env vars into the bundle at build time: VITE_BASE_PATH for path-mounted standalones, VITE_LNBITS_BASE_URL / VITE_NOSTR_RELAYS / VITE_LIGHTNING_DOMAIN / etc. for per-deployment service URLs. extraEnv is merged on top of the brand kit + sandbox defaults (BRAND_DIR, BRAND_APP, CI). Brand-controlled vars (VITE_APP_NAME via brand.name) stay strict — the vite configs internally set process.env.VITE_APP_NAME from brand.json after the derivation starts, so an extraEnv attempt at VITE_APP_NAME is a no-op (by design, per #99 strict-from-the-start). Per-host name customization flows through per-host brandDir, not env vars. Verified VITE_BASE_PATH=/events/ via extraEnv emits hrefs prefixed with /events/ in the built events.html. Co-Authored-By: Claude Opus 4.7 (1M context) --- flake.nix | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 588438c..14859ec 100644 --- a/flake.nix +++ b/flake.nix @@ -19,7 +19,7 @@ inherit (pkgs.stdenv.hostPlatform) system; }; - mkWebapp = { pkgs, brandDir ? ./branding/default, app ? "main" }: + mkWebapp = { pkgs, brandDir ? ./branding/default, app ? "main", extraEnv ? {} }: let buildScript = if app == "main" then "build" else "build:${app}"; outDir = if app == "main" then "dist" else "dist-${app}"; @@ -59,13 +59,19 @@ # pwa-assets.config.ts. brandDir is either ./branding/default # (a path inside this flake's source) or an external path that # nix has copied into the build sandbox. + # + # `extraEnv` flows in VITE_* and any other build-time env vars + # the caller wants to bake into the bundle (e.g. webapp-module + # passes VITE_NOSTR_RELAYS / VITE_LNBITS_BASE_URL / …; the + # server-deploy standalones module passes VITE_BASE_PATH + + # VITE_APP_NAME for per-app path mounts). env = { BRAND_DIR = "${brandDir}"; BRAND_APP = if app == "main" then "" else app; # Avoid pnpm 10's interactive modules-purge prompt in the # sandbox (ERR_PNPM_ABORTED_REMOVE_MODULES_DIR_NO_TTY). CI = "true"; - }; + } // extraEnv; buildPhase = '' runHook preBuild