Issue with building native npm module

I have nodejs-8_x in buildInputs of haskell.lib.buildStackProject in shell.nix,

with (import <nixpkgs> { });

haskell.lib.buildStackProject {
  name = "tcr";
  buildInputs = [ nodejs-8_x pkgs.postgresql.lib pkgs.postgresql.out postgresql openssl.dev openssl.out clang git ncurses zlib autoreconfHook xz flyway ];
  libraryHaskellDepends = [ postgresql.lib openssl.out openssl.dev ];
  inherit ghc;

  meta = {
    platforms = stdenv.lib.platforms.unix;
  };
}

But when I enter into nix-shell, and do npm i build of some native npm module is started and I get an error

libtool:   error: unrecognised option: '-static'

As I understand it’s because libtool is installed as part of nix-shell and that one is used when npm is building that module, while the module is passing osx specific arguments to libtool.

if I do which -a libtool in terminal I get :

/usr/bin/libtool

but if I do it inside nix-shell, I get:

/nix/store/3z3ybxz5hzavkc8i7pgapb238yj49x96-libtool-2.4.6/bin/libtool
/usr/bin/libtool

What I’m doing to overcome the issue is I have nodejs installed globally (using nix too) and I do npm i there (onstead of from nix-shell) and it’s using regular osx version of libtool from /usr/bin/libtool and works fine, then I enter into nix-shell and work from there.

(the npm module is scrypt)

I’m interested in how should one approach such issue and what could be a possible fix.

This looks like this issue:

https://github.com/nodejs/node/issues/2341

Basically node-gyp is really dumb in handling libtool. Putting darwin.cctools in nativeBuildInputs should fix this for you. But to be clear this is a node-gyp bug, not a Nixpkgs one!

1 Like

thanks putting darwin.cctools in nativeBuildInputs helped!

1 Like