build: switch from buildNpmPackage to pnpm.configHook
Webapp now uses pnpm (aiolabs/webapp#61); fetch deps from pnpm-lock.yaml instead of package-lock.json. - Replace buildNpmPackage with stdenv.mkDerivation + pnpm.fetchDeps - Rename npmDepsHash option to pnpmDepsHash - Drop npmFlags and makeCacheWritable (handled by pnpm.configHook) Consumers must update their pnpmDepsHash. Set to lib.fakeHash on first build to get the correct hash.
This commit is contained in:
parent
b36b3dbf61
commit
391f8006fd
1 changed files with 21 additions and 21 deletions
42
webapp.nix
42
webapp.nix
|
|
@ -4,8 +4,8 @@
|
||||||
let
|
let
|
||||||
cfg = config.services.webapp;
|
cfg = config.services.webapp;
|
||||||
|
|
||||||
# Build the Vue 3 webapp using buildNpmPackage
|
# Build the Vue 3 webapp using stdenv + pnpm.configHook
|
||||||
webapp = pkgs.buildNpmPackage {
|
webapp = pkgs.stdenv.mkDerivation (finalAttrs: {
|
||||||
pname = "aio-webapp";
|
pname = "aio-webapp";
|
||||||
version = "1.0.0";
|
version = "1.0.0";
|
||||||
|
|
||||||
|
|
@ -15,17 +15,15 @@ let
|
||||||
ref = cfg.gitRef;
|
ref = cfg.gitRef;
|
||||||
};
|
};
|
||||||
|
|
||||||
# SHA256 hash of npm dependencies
|
# Fixed-output derivation of the pnpm offline store.
|
||||||
# Run `nix-prefetch-npm-deps package-lock.json` to get this hash
|
# On first build / lockfile change, set hash = lib.fakeHash and rebuild;
|
||||||
# Or use lib.fakeHash initially and let the build tell you the correct hash
|
# Nix will report the correct hash to substitute.
|
||||||
npmDepsHash = cfg.npmDepsHash;
|
pnpmDeps = pkgs.pnpm.fetchDeps {
|
||||||
|
inherit (finalAttrs) pname version src;
|
||||||
|
hash = cfg.pnpmDepsHash;
|
||||||
|
};
|
||||||
|
|
||||||
# Node.js version (use LTS)
|
nativeBuildInputs = [ pkgs.nodejs_20 pkgs.pnpm.configHook ];
|
||||||
nodejs = pkgs.nodejs_20;
|
|
||||||
|
|
||||||
# Include devDependencies (vue-tsc, vite, etc. are needed for build)
|
|
||||||
npmFlags = [ "--include=dev" ];
|
|
||||||
makeCacheWritable = true;
|
|
||||||
|
|
||||||
# Skip Electron binary download (we're building a web app, not desktop)
|
# Skip Electron binary download (we're building a web app, not desktop)
|
||||||
ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
|
ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
|
||||||
|
|
@ -79,10 +77,12 @@ let
|
||||||
# Additional env vars
|
# Additional env vars
|
||||||
NODE_ENV = "production";
|
NODE_ENV = "production";
|
||||||
|
|
||||||
# Explicitly add node_modules/.bin to PATH for vue-tsc, vite, etc.
|
# pnpm.configHook sets up the offline store and runs
|
||||||
|
# `pnpm install --offline --frozen-lockfile` before buildPhase.
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
export PATH="$PWD/node_modules/.bin:$PATH"
|
runHook preBuild
|
||||||
npm run build
|
pnpm run build
|
||||||
|
runHook postBuild
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Install the built static files (Vite outputs to ./dist)
|
# Install the built static files (Vite outputs to ./dist)
|
||||||
|
|
@ -93,7 +93,7 @@ let
|
||||||
runHook postInstall
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Don't run npm test
|
# Don't run pnpm test
|
||||||
doCheck = false;
|
doCheck = false;
|
||||||
|
|
||||||
meta = with lib; {
|
meta = with lib; {
|
||||||
|
|
@ -101,7 +101,7 @@ let
|
||||||
license = licenses.mit;
|
license = licenses.mit;
|
||||||
platforms = platforms.linux;
|
platforms = platforms.linux;
|
||||||
};
|
};
|
||||||
};
|
});
|
||||||
|
|
||||||
in {
|
in {
|
||||||
options.services.webapp = {
|
options.services.webapp = {
|
||||||
|
|
@ -135,13 +135,13 @@ in {
|
||||||
description = "Domain name for the webapp";
|
description = "Domain name for the webapp";
|
||||||
};
|
};
|
||||||
|
|
||||||
npmDepsHash = lib.mkOption {
|
pnpmDepsHash = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
default = lib.fakeHash;
|
default = lib.fakeHash;
|
||||||
description = ''
|
description = ''
|
||||||
SHA256 hash of npm dependencies.
|
SRI hash of pnpm dependencies fetched from `pnpm-lock.yaml`.
|
||||||
Run `nix-prefetch-npm-deps package-lock.json` on the webapp source
|
Initially set to `lib.fakeHash`; on first build with a new lockfile,
|
||||||
to get the correct hash.
|
Nix will fail with the correct hash to substitute in.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue