nixpkgs/pkgs/top-level/node-packages.nix
Shea Levy 239d532095 node-packages.nix: Convert to new npm2nix style
Starting with 1.0.0 (which is not released at the time of this commit
but will be before it is pushed), npm2nix takes a JSON file with a list
of names (and optionally version ranges) and generates a data-only (no
functions, no rec, no let, etc.) nix expression representing the
packages with those names and their dependencies.

node-packages.nix now builds its package list from that generated
expression. If a package needs native dependencies as build inputs, they
can be added to the nativeDeps attribute set. If a package cannot be
generated by npm2nix for some reason, it can be added manually to the
set.

I tried to capture the packages represented by the previous
node-packages.nix in the new node-packages.json, but I almost certainly
missed some that will have to be added manually.

Signed-off-by: Shea Levy <shea@shealevy.com>
2013-05-27 22:35:20 -04:00

45 lines
1.5 KiB
Nix

{ pkgs, stdenv, nodejs, fetchurl, neededNatives }:
let
generated = builtins.listToAttrs (pkgs.lib.fold (pkg: pairs:
(pkgs.lib.optional pkg.topLevel { name = pkg.baseName; value = builtins.getAttr pkg.fullName self; }) ++ [
{
name = pkg.fullName;
value = self.buildNodePackage rec {
name = "${pkg.baseName}-${pkg.version}";
src = (if pkg.patchLatest then self.patchLatest else fetchurl) {
url = "http://registry.npmjs.org/${pkg.baseName}/-/${name}.tgz";
sha256 = pkg.hash;
};
deps = map (dep: builtins.getAttr "${dep.name}-${dep.range}" self) pkg.dependencies;
buildInputs = if builtins.hasAttr name nativeDeps then builtins.getAttr name nativeDeps else [];
};
}
] ++ pairs
) [] (import ./node-packages-generated.nix));
nativeDeps = {
"node-expat-*" = [ pkgs.expat ];
"rbytes-0.0.2" = [ pkgs.openssl ];
};
self = {
buildNodePackage = import ../development/web/nodejs/build-node-package.nix {
inherit stdenv nodejs neededNatives;
inherit (pkgs) runCommand;
};
patchLatest = srcAttrs:
let src = fetchurl srcAttrs; in pkgs.runCommand src.name {} ''
mkdir unpack
cd unpack
tar xf ${src}
mv */ package 2>/dev/null || true
sed -i -e "s/: \"latest\"/: \"*\"/" package/package.json
tar cf $out *
'';
/* Put manual packages below here (ideally eventually managed by npm2nix */
} // generated;
in self