Split into modules and reorganize

This commit is contained in:
Stéphan Kochen
2020-08-25 18:55:38 +02:00
parent 708e36eaf4
commit 5d3ed3c119
10 changed files with 241 additions and 225 deletions
+96
View File
@@ -0,0 +1,96 @@
# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!
{ lib, coreutils, nodejs, stdenv }: src:
let
yarnPath = @@YARN_PATH@@;
cacheFolder = @@CACHE_FOLDER@@;
cacheEntries = @@CACHE_ENTRIES@@;
# Fetch a single dependency.
fetchOne = let
builder = builtins.toFile "builder.sh" ''
source $stdenv/setup
cd "$src"
HOME="$TMP" yarn_cache_folder="$TMP" CI=1 \
node '${yarnPath}' nixify fetch-one $locatorHash
mv "$TMP/$outputFilename" $out
'';
in { name, filename, sha512, locatorHash }: stdenv.mkDerivation {
inherit name src builder locatorHash;
buildInputs = [ nodejs ];
outputFilename = filename;
outputHashMode = "flat";
outputHashAlgo = "sha512";
outputHash = sha512;
};
# Shell snippet to collect all project dependencies.
collectCache = lib.concatMapStrings (args: ''
cp ${fetchOne args} '${args.filename}'
'') cacheEntries;
in stdenv.mkDerivation {
name = @@PROJECT_NAME@@;
inherit src;
# Tell node-gyp to use the provided Node.js headers for native code builds.
npm_config_nodedir = nodejs;
# Tell node-pre-gyp to never fetch binaries / always build from source.
npm_config_build_from_source = "true";
# Make sure the build uses the right Node.js version everywhere.
buildInputs = [ nodejs ];
# Defines the shell alias to run Yarn.
postHook = ''
yarn() {
CI=1 node "$NIX_YARN_PATH" "$@"
}
'';
configurePhase = ''
runHook preConfigure
# Copy over the Yarn cache.
# TODO: Can we do without the copy somehow? Links don't work.
rm -fr '${cacheFolder}'
mkdir -p '${cacheFolder}'
pushd '${cacheFolder}' > /dev/null
${collectCache}
popd > /dev/null
# Store the absolute path to Yarn for the 'yarn' alias.
export NIX_YARN_PATH="$(readlink -f '${yarnPath}')"
# Run normal Yarn install to complete dependency installation.
yarn install --immutable --immutable-cache
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/libexec $out/bin
# Move the entire project to the output directory.
mv $PWD "$out/libexec/$sourceRoot"
cd "$out/libexec/$sourceRoot"
# Update the path to Yarn.
export NIX_YARN_PATH="$(readlink -f '${yarnPath}')"
# Invoke a plugin internal command to setup binaries.
yarn nixify install-bin $out/bin
runHook postInstall
'';
}