Skip to content

Commit

Permalink
Extract node_modules building
Browse files Browse the repository at this point in the history
Building the `node_modules` folder is not actually purescript specific
and is more of an input so this commit splits off the use of
npmlock2nix for building a `node_modules` output to node_modules.nix and
a `buildNodeModules` function in `plutus.lib.buildNodeModules`
  • Loading branch information
gilligan committed Nov 24, 2020
1 parent 8c1cd48 commit 0fa1635
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
28 changes: 28 additions & 0 deletions nix/lib/node_modules.nix
@@ -0,0 +1,28 @@
{ npmlock2nix
, nodejs
, python2
, stdenv
, lib
, CoreServices ? null # needed by darwin only
, xcodebuild ? null # needed by darwin only
}:
let
# Takes a source and extracts `package.json, package-lock.json` from it
# Type: Path -> Path
getPackageFiles = src: lib.cleanSourceWith {
filter = (path: type: lib.elem (baseNameOf path) [ "package.json" "package-lock.json" ]);
inherit src;
};
in
# Description: Takes a `projectDir` path to a directory containing a `package.json` and a `package-lock.json`
# and creates an output containing `node_modules/, package.json, package-lock.json`. The `buildInputs`
# will be avaibale during `npm install`
# Type: Attr { projectDir: Path, buildInputs: List } -> Derivation
{ projectDir, buildInputs ? [ ] }:
npmlock2nix.node_modules {
inherit nodejs;
src = getPackageFiles projectDir;
buildInputs = [ python2 ]
++ lib.optionals (stdenv.isDarwin) [ CoreServices xcodebuild ]
++ buildInputs;
}
25 changes: 4 additions & 21 deletions nix/lib/purescript.nix
@@ -1,27 +1,19 @@
{ stdenv
, lib
, cacert
, nodejs
, nodePackages
, python2
, git
, fetchurl
, npmlock2nix
, nodejs-headers
, easyPS
, CoreServices ? null # darwin only
, xcodebuild ? null # darwin only
, buildNodeModules
}:

{ psSrc
, src
, name
, additionalPurescriptSources ? [ ]
, additionalNpmBuildInputs ? [ ]
, packages
, spagoPackages
, webCommon
, checkPhase ? ""
, passthru ? { }
}:
let
cleanSrcs = lib.cleanSourceWith {
Expand All @@ -33,28 +25,19 @@ let
};
};

packageLockJson = lib.cleanSourceWith {
filter = (path: type: lib.elem (baseNameOf path) [ "package.json" "package-lock.json" ]);
inherit src;
};

purescriptSources = [
"src/**/*.purs"
"test/**/*.purs"
"generated/**/*.purs"
".spago/*/*/src/**/*.purs"
] ++ additionalPurescriptSources;

nodeModules = npmlock2nix.node_modules {
inherit nodejs;
src = packageLockJson;
buildInputs = [ python2 ] ++ lib.optionals (stdenv.isDarwin) [ CoreServices xcodebuild ];
};
nodeModules = buildNodeModules { projectDir = src; buildInputs = additionalNpmBuildInputs; };
in
stdenv.mkDerivation {
name = "plutus-playground-client";
src = cleanSrcs;
buildInputs = [ nodeModules easyPS.purs easyPS.spago easyPS.psc-package python2 ];
buildInputs = [ nodeModules easyPS.purs easyPS.spago easyPS.psc-package ];
buildPhase = ''
export HOME=$NIX_BUILD_TOP
shopt -s globstar
Expand Down
13 changes: 6 additions & 7 deletions nix/pkgs/default.nix
Expand Up @@ -147,16 +147,15 @@ let
haddock-combine = pkgs.callPackage ../lib/haddock-combine.nix { inherit sphinxcontrib-haddock; };
latex = pkgs.callPackage ../lib/latex.nix { };
npmlock2nix = (import sources.npmlock2nix { });
buildPursPackage = pkgs.callPackage ../lib/purescript.nix ({
inherit easyPS nodejs-headers npmlock2nix;
CoreServices = if stdenv.isDarwin then pkgs.darwin.apple_sdk.frameworks.CoreServices else null;
xcodebuild = if stdenv.isDarwin then pkgs.xcodebuild else null;
buildPursPackage = pkgs.callPackage ../lib/purescript.nix { inherit easyPS buildNodeModules;inherit (pkgs) nodejs; };
buildNodeModules = pkgs.callPackage ../lib/node_modules.nix ({
inherit npmlock2nix;
} // pkgs.lib.optionalAttrs (stdenv.isDarwin) {
inherit (pkgs.darwin.apple_sdk.frameworks) CoreServices;
inherit (pkgs) xcodebuild;
CoreServices = pkgs.darwin.apple_sdk.frameworks.CoreServices;
xcodebuild = pkgs.xcodebuild;
});
};

};

in
{
Expand Down

0 comments on commit 0fa1635

Please sign in to comment.