[Nix-dev] Node.JS package and build inputs

Mathijs Kwik mathijs at bluescreen303.nl
Mon Feb 4 13:25:32 CET 2013


Sander van der Burg - EWI <S.vanderBurg at tudelft.nl> writes:

> Hi everyone,
>
> Lately, I'm using Node.js and I wanted to create a package that requires some of the
> NodeJS modules that we have defined in node-packages.nix. However, when I add them to
> buildInputs, they cannot be found.
>
> Of course, I could set the NODE_PATH environment variable in every package expression
> that I write, but I find it more elegant when we can just add these to buildInputs.
>
> Enabling this functionality is not that hard. We just have to provide a setup hook with
> Node.js that adds packages with a node_modules subdirectory to NODE_PATH. I can
> implement that hook quite easily.
>
> What do you think?

I do something similar, I create a "virtual" package, containing just
the dependencies for my project. The output of this package is a dir 
that contains a valid node_modules dir for my project.

modules = node.buildNodePackage rec {
            name = "my-project-modules";
            phases = [ "configurePhase" "installPhase"];
            src = runCommand "empty-dir" {} "mkdir $out";
            deps = [
              node."coffee-script-1.4.0"
              node."less-1.3.0"
              node."cssmin-0.3.1"
              node."underscore-1.4.2"
              node."backbone-0.9.2"
              node."showdown-0.0.1"
              node."datetime-0.0.3"
              node."mrclean-0.1.0"
              node."escape-html-0.0.1"
              node."mongodb-1.1.11"
              node."connect-2.4.4"
              node."hat-0.0.3"
              node."sockjs-0.3.1"
              node."ws-0.4.21"
              node."source-map-0.1.2"
              node."async-0.1.22"
              node."wu-0.1.8"
            ];
          };

Then my project itself just links this directory:

stdenv.mkDerivation rec {
  name = "my-project-1.3";

  src = fetchgit { ... };

  buildInputs = [nginx nodejs redis modules];

  configurePhase = ''
    ln -s ${modules}/node_modules .
    ...
  '';

  installPhase = ''
    mkdir -p $out/share/my-project
    ...
    ln -s ${modules}/node_modules $out/share/my-project
  '';
}


This has the added advantage that I can use this modules-dir from my
development environment as well by creating a simple symlink.

Mathijs


>
> -- Sander
>
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev


More information about the nix-dev mailing list