Node2Nix Issues

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

with import <nixpkgs> { };
stdenv.mkDerivation {
  name = "env";
  nativeBuildInputs = [ pkg-config ];
  buildInputs = [
    autoreconfHook
    xorg.libX11
    xorg.libXi
    xorg.libXext
    libGLU
    zlib
    glibc.out
    glibc.static
    libpng
    nasm
    cairo
    pango
    libuuid # canvas
  ];

  # workaround for npm dep compilation
  # https://github.com/imagemin/optipng-bin/issues/108
  shellHook = ''
    LD=$CC
  '';
}
$ nix-shell build.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. https://stackoverflow.com/questions/69953573/nodejs-headless-gl-null-in-nixos/69953610?noredirect=1#comment123682825_69953610
  # https://github.com/albertgoncalves/ranim/blob/e59ee646c155fefba69b6f3b9aaad0402d360c2e/shell.nix#L37
  # test with `echo $LD_LIBRARY_PATH` after entering with nix-shell
  APPEND_LIBRARY_PATH = "${lib.makeLibraryPath [ libGL libuuid ]}";
  shellHook = ''
    export LD_LIBRARY_PATH="$APPEND_LIBRARY_PATH:$LD_LIBRARY_PATH"
  '';
}
$ nix-shell run.nix

$ echo $LD_LIBRARY_PATH | tr ':' '\n'
/nix/store/8pj8n7g8cfbbra79lmhc93nk5nv92drk-util-linux-2.37.2/lib
/nix/store/5icl3gj83q5ar5klx2lc61qyll669inw-libGL-1.3.4/lib
/nix/store/yxflij8cg4fgnzqmda91jx4d94jvkjf5-util-linux-2.37.2-lib/lib
/nix/store/ikh86qfbsi23iajdpbrf642q6v612cw8-telepathy-glib-0.24.2/lib
/nix/store/m8bmifhlakz1mlsz37ki6cwfw2nxry66-telepathy-logger-0.8.2/lib

$ node index.js

util-linux contains libuuid.

I see that discord also uses lib.makeLibraryPath:

1 Like