nzbr / pnpm2nix-nzbr

Build packages using pnpm with nix
ISC License
62 stars 23 forks source link

some problems about building next.js packages with connectrpc #32

Closed alissa-tung closed 9 months ago

alissa-tung commented 9 months ago

your project are great! thank you for developing a nice and well documented tool for pnpm & nix.

hello, I am trying to build an application using next.js packages and connectrpc. I am not sure whether my problems are related to this project's scope. If not please feel free to close this issue

my questions are

  1. how can I build a next.js project using the next fonts features in sandbox mode? https://nextjs.org/docs/app/building-your-application/optimizing/fonts which needs to access web to downloads fonts. is there any suggested ways to do the "download the source, then add to source tree" stuff?
  2. how can I run some custom scripts to generate some code? like the pnpm exec buf generate a.proto? the issue is difficult is because pnpm exec buf generate needs the devDeps in package.json is installed by pnpm. I had tried to sed to modify the package.json the build field. but seems that does not work just patch the build scripts
alissa-tung commented 9 months ago

I had tried to run something like

  patchPhase = ''
    sed -i "s|next build|pnpm exec buf generate \${x-proto}/x.proto \&\& ls lib/gen/x/v1 \&\& next build|g" ./package.json
    cat ./package.json | grep 'build'
  '';

the logs said the grep is okay, but the buf generate does not create dir

Running phase: buildPhase

> x@0.1.0 build /build/x
> pnpm exec buf generate /nix/store/a-x-proto-0.0.0/x.proto && ls lib/gen/x/v1 && next build

ls: cannot access 'lib/gen/x/v1': No such file or directory
 ELIFECYCLE  Command failed with exit code 2.
alissa-tung commented 9 months ago

turns out buf generate is my problem, that is, buf generate accepts a path x/y/z, where the output path structure is relative

alissa-tung commented 9 months ago

I had tried to make a drv FOD to access to the network

mkPnpmPackage {
  outputHashAlgo = "sha256";
  outputHashMode = "recursive";
  outputHash = "";
}

but seems that Nix still does not allow this drv to access network. 🤔

nzbr commented 9 months ago

I do not know of any way to convince nextjs do use a pre-downloaded font when using the google fonts package (haven't used it personally yet). You can of course use a local font instead and supply the font files either through pnpm or through nix. As for the codegen: Instead of patching the package.json, I recommend you use preBuild instead. That should run as the first thing in the buildPhase and you can just run pnpm exec buf generate ... in there

alissa-tung commented 9 months ago

Thank you. I am still trying to find out why the above FOD does not work and node said UNABLE_TO_GET_ISSUER_CERT_LOCALLY but all of them are not quite relevant to this project's scope. Anyway thank you for developing this project. If someone sees this issue, I would like to tell this may be the only usable pnpm2nix like project, and it does can package pnpm packages.