How to package a pnpm project

Anyone here that has packaged a pnpm project? SvelteKit to be more specific.

The devbox approach looks reasonable.
The flake is wrote makes me want to cry and does not even work correctly.

Any pointer to an example or some best practice - especially in regards to the locked dependencies?

If you use my flake template i made the following that you can put in nix/node.nix:

{
  perSystem =
    {
      pkgs,
      ...
    }:
    {
      make-shells.default = {
        packages = [
          pkgs.nodejs_25
          pkgs.pnpm_10
        ];

        shellHook = ''
          export PATH=$PATH:node_modules/.bin/
        '';
      };

      packages.default =
        let
          pnpmDeps = pkgs.fetchPnpmDeps {
            pname = "your-project-name-pnpm-deps";
            version = "your-version";
            src = ../.;
            pnpm = pkgs.pnpm_10;
            fetcherVersion = 3; # See https://nixos.org/manual/nixpkgs/stable/#javascript-pnpm-fetcherVersion
            # Change the hash when pnpm-lock.yaml updates, you can get the hash by setting it to "" and running `nix build .#default`
            hash = "";
          };
        in
        pkgs.stdenv.mkDerivation {
          pname = "your-project-name";
          version = "your-version";
          src = ../.;
          inherit pnpmDeps;

          nativeBuildInputs = [
            pkgs.nodejs_25
            pkgs.pnpmConfigHook
            pkgs.pnpm_10
            pkgs.makeWrapper
          ];

          buildPhase = ''
            pnpm build
          '';

          installPhase = ''
            cp -r build $out
            makeWrapper ${pkgs.nodejs_25}/bin/node $out/bin/your-project-name --add-flag $out/index.js
          '';
        };
    };
}

You can then run nix build .#default and run result/bin/your-project-name.