feat(nix): lib.mkWebapp accepts extraEnv attr #100

Merged
padreug merged 1 commit from feat/lib-mkwebapp-extraenv into dev 2026-06-10 15:05:12 +00:00
Owner

Unblocks the strategic deploy fix on the server-deploy / webapp-module side. Without this, callers can't bake VITE_BASE_PATH, VITE_LNBITS_BASE_URL, etc. into the build through lib.mkWebapp and have to fall back to their own derivations (the duplicated-hash problem that caused #99).

Change

lib.mkWebapp grows an extraEnv ? {} attr. It merges on top of the brand kit + sandbox defaults (BRAND_DIR, BRAND_APP, CI) and feeds the derivation's env.

inputs.webapp.lib.mkWebapp {
  inherit pkgs;
  app = "events";
  extraEnv = {
    VITE_BASE_PATH = "/events/";
    VITE_LNBITS_BASE_URL = "https://lnbits.demo.aiolabs.dev";
    # …
  };
}

Strict carve-out

VITE_APP_NAME via extraEnv is a no-op by design: the per-app vite configs (vite.events.config.ts etc.) internally set process.env.VITE_APP_NAME = brand.name after the derivation starts, overwriting the env value. This is exactly the strict behavior #99 landed — brand name flows through brand.json only.

Per-host name customization should go through per-host brandDir (server-deploy migration tracked separately). Documenting this here so the next person who tries to override VITE_APP_NAME via extraEnv doesn't waste time debugging.

Test plan

  • nix build .#main — unchanged
  • nix build --impure --expr '...lib.mkWebapp { pkgs; app = "events"; extraEnv = { VITE_BASE_PATH = "/events/"; }; }' — built events.html has href="/events/icons/favicon.ico" etc., proving the env baked in
  • aio-demo deploy via downstream server-deploy refactor

🤖 Generated with Claude Code

Unblocks the strategic deploy fix on the server-deploy / webapp-module side. Without this, callers can't bake `VITE_BASE_PATH`, `VITE_LNBITS_BASE_URL`, etc. into the build through `lib.mkWebapp` and have to fall back to their own derivations (the duplicated-hash problem that caused #99). ## Change `lib.mkWebapp` grows an `extraEnv ? {}` attr. It merges on top of the brand kit + sandbox defaults (`BRAND_DIR`, `BRAND_APP`, `CI`) and feeds the derivation's env. ```nix inputs.webapp.lib.mkWebapp { inherit pkgs; app = "events"; extraEnv = { VITE_BASE_PATH = "/events/"; VITE_LNBITS_BASE_URL = "https://lnbits.demo.aiolabs.dev"; # … }; } ``` ## Strict carve-out `VITE_APP_NAME` via `extraEnv` is a **no-op by design**: the per-app vite configs (`vite.events.config.ts` etc.) internally set `process.env.VITE_APP_NAME = brand.name` after the derivation starts, overwriting the env value. This is exactly the strict behavior #99 landed — brand name flows through `brand.json` only. Per-host name customization should go through per-host `brandDir` (server-deploy migration tracked separately). Documenting this here so the next person who tries to override `VITE_APP_NAME` via `extraEnv` doesn't waste time debugging. ## Test plan - [x] `nix build .#main` — unchanged - [x] `nix build --impure --expr '...lib.mkWebapp { pkgs; app = "events"; extraEnv = { VITE_BASE_PATH = "/events/"; }; }'` — built `events.html` has `href="/events/icons/favicon.ico"` etc., proving the env baked in - [ ] aio-demo deploy via downstream server-deploy refactor 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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) <noreply@anthropic.com>
padreug deleted branch feat/lib-mkwebapp-extraenv 2026-06-10 15:05:13 +00:00
Sign in to join this conversation.
No description provided.