Node2Nix Issues

I’ve been trying all day to get a node/React app ( running on my new NixOS install. It has been hanging up on canvas. My branch with my attempts at getting it working is which used node2nix with a wrapper and a flakes.nix. So my first issue was that canvas couldn’t find node-pre-gyp to build with so I had to add it to the buildInputs. Then it was failing to build canvas since it couldn’t download the prebuilt and I hadn’t included the dependencies for it. After spending quite a while down a rabbit hole trying to get the prebuilt working I realized that when building flakes it blocks internet access from the build. In the meantime I tried building new versions of node-pre-gyp with supplement.json to try and get a fix to an issue with needle not working. It wouldn’t compile so I ended up using @discordjs/node-pre-gyp which did work. I finally ended up having to also put all the dependencies for canvas in the buildInputs.

Then I got the environment built, but when trying to run it with npm run devstart it errored out that it couldn’t find babel-loader which was missing from the .bin even though it did seem to list it as a dependency in the generated nix files. I’ve tried adding it to supplement.json where it failed to build due to missing yarn and then needing an internet connection.

I can get a little farther by running npm install inside of the nix develop environment which I know is antithetical to the Nix paradigm. That errors out on devstart as well just this time due to canvas not being able to find even though there is libuuid in the build inputs.

Anyone have any ideas on what I’m doing wrong? I’m quite new to Nix.

1 Like

This is my build.nix (you only need libuuid I suppose):

with import <nixpkgs> { };
stdenv.mkDerivation {
  name = "env";
  nativeBuildInputs = [ pkg-config ];
  buildInputs = [
    libuuid # canvas

  # workaround for npm dep compilation
  shellHook = ''
$ nix-shell
$ npm install

and this is my run.nix:

{ pkgs ? import <nixpkgs> { } }:
with pkgs; mkShell {
  name = "node-dev-shell";
  # Attributes aren't interpolated by the shell, so $LD_LIBRARY_PATH ends up verbatim in your environment. You could remove it (if no users of this expr need it) or convert it to an export statement in shellHook, which runs as regular bash, including interpolation.
  # test with `echo $LD_LIBRARY_PATH` after entering with nix-shell
  APPEND_LIBRARY_PATH = "${lib.makeLibraryPath [ libGL libuuid ]}";
  shellHook = ''
$ nix-shell run.nix

$ echo $LD_LIBRARY_PATH | tr ':' '\n'

$ node index.js

util-linux contains libuuid.

I see that discord also uses lib.makeLibraryPath:

1 Like