166 lines
6.1 KiB
Nix
166 lines
6.1 KiB
Nix
# This file is generated by running "yarn install" inside your project.
|
|
# Manual changes might be lost - proceed with caution!
|
|
|
|
{ lib, stdenv, nodejs, git, cacert, fetchurl, writeShellScript, writeShellScriptBin }:
|
|
{ src, overrideAttrs ? null, ... } @ args:
|
|
|
|
let
|
|
|
|
yarnBin = fetchurl {
|
|
url = "https://repo.yarnpkg.com/4.14.1/packages/yarnpkg-cli/bin/yarn.js";
|
|
hash = "sha512-ZN9EgFWy03uiadfbU1pGm42pP47xFAwl/XqDwAqPuqyyFMoOAlU7kqLFTO94u2fQtIF/qwIAHfDiT6wPrMw7Qg==";
|
|
};
|
|
|
|
cacheFolder = ".yarn/cache";
|
|
lockfile = ./yarn.lock;
|
|
|
|
# Call overrideAttrs on a derivation if a function is provided.
|
|
optionalOverride = fn: drv:
|
|
if fn == null then drv else drv.overrideAttrs fn;
|
|
|
|
# Simple stub that provides the global yarn command.
|
|
yarn = writeShellScriptBin "yarn" ''
|
|
exec '${nodejs}/bin/node' '${yarnBin}' "$@"
|
|
'';
|
|
|
|
# Common attributes between Yarn derivations.
|
|
drvCommon = {
|
|
# Make sure the build uses the right Node.js version everywhere.
|
|
buildInputs = [ nodejs yarn ];
|
|
# All dependencies should already be cached.
|
|
yarn_enable_network = "0";
|
|
# Tell node-gyp to use the provided Node.js headers for native code builds.
|
|
npm_config_nodedir = nodejs;
|
|
};
|
|
|
|
# Comman variables that we set in a Nix build, but not in a Nix shell.
|
|
buildVars = ''
|
|
# Make Yarn produce friendlier logging for automated builds.
|
|
export CI=1
|
|
# Tell node-pre-gyp to never fetch binaries / always build from source.
|
|
export npm_config_build_from_source=true
|
|
'';
|
|
|
|
# Create derivations for fetching dependencies.
|
|
cacheDrvs = let
|
|
in lib.mapAttrs (locator: { filename, hash }: stdenv.mkDerivation {
|
|
name = lib.strings.sanitizeDerivationName locator;
|
|
buildInputs = [ yarn git cacert ];
|
|
buildCommand = ''
|
|
cd '${src}'
|
|
${buildVars}
|
|
HOME="$TMP" yarn_enable_global_cache=false yarn_cache_folder="$TMP" \
|
|
yarn nixify fetch ${lib.escapeShellArg locator}
|
|
# Because we change the cache dir, Yarn may generate a different name.
|
|
mv "$TMP/$(sed 's/-[^-]*\.[^-]*$//' <<< "$outputFilename")"-* $out
|
|
'';
|
|
outputFilename = filename;
|
|
outputHash = hash;
|
|
}) cacheEntries;
|
|
|
|
# Create a shell snippet to copy dependencies from a list of derivations.
|
|
mkCacheBuilderForDrvs = drvs:
|
|
writeShellScript "collect-yarn-cache" (lib.concatMapStrings (drv: ''
|
|
cp --reflink=auto ${drv} '${drv.outputFilename}'
|
|
'') drvs);
|
|
|
|
# Main project derivation.
|
|
project = stdenv.mkDerivation (drvCommon // {
|
|
inherit src;
|
|
name = "@quixos/camino-datatypes";
|
|
|
|
configurePhase = ''
|
|
${buildVars}
|
|
|
|
# Copy over the Yarn cache.
|
|
rm -fr '${cacheFolder}'
|
|
mkdir -p '${cacheFolder}'
|
|
pushd '${cacheFolder}' > /dev/null
|
|
source ${mkCacheBuilderForDrvs (lib.attrValues cacheDrvs)}
|
|
popd > /dev/null
|
|
|
|
# Yarn may need a writable home directory.
|
|
export yarn_global_folder="$TMP"
|
|
|
|
# Ensure global cache is disabled. Cache must be part of our output.
|
|
touch .yarnrc.yml
|
|
sed -i -e '/^enableGlobalCache/d' .yarnrc.yml
|
|
echo 'enableGlobalCache: false' >> .yarnrc.yml
|
|
|
|
# Some node-gyp calls may call out to npm, which could fail due to an
|
|
# read-only home dir.
|
|
export HOME="$TMP"
|
|
|
|
# running preConfigure after the cache is populated allows for
|
|
# preConfigure to contain substituteInPlace for dependencies as well as the
|
|
# main project. This is necessary for native bindings that maybe have
|
|
# hardcoded values.
|
|
runHook preConfigure
|
|
|
|
# Run normal Yarn install to complete dependency installation.
|
|
yarn install --immutable --immutable-cache
|
|
|
|
runHook postConfigure
|
|
'';
|
|
|
|
buildPhase = ''
|
|
runHook preBuild
|
|
runHook postBuild
|
|
'';
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
|
|
# Move the package contents to the output directory.
|
|
if grep -q '"workspaces"' package.json; then
|
|
# We can't use `yarn pack` in a workspace setup, because it only
|
|
# packages the outer workspace.
|
|
mkdir -p "$out/libexec"
|
|
mv $PWD "$out/libexec/$name"
|
|
else
|
|
# - If the package.json has a `files` field, only files matching those patterns are copied
|
|
# - Otherwise all files are copied.
|
|
yarn pack --out package.tgz
|
|
mkdir -p "$out/libexec/$name"
|
|
tar xzf package.tgz --directory "$out/libexec/$name" --strip-components=1
|
|
|
|
cp --reflink=auto .yarnrc* "$out/libexec/$name"
|
|
cp --reflink=auto ${lockfile} "$out/libexec/$name/yarn.lock"
|
|
cp --reflink=auto --recursive .yarn "$out/libexec/$name"
|
|
|
|
# Copy the Yarn linker output into the package.
|
|
cp --reflink=auto --recursive node_modules "$out/libexec/$name"
|
|
fi
|
|
|
|
cd "$out/libexec/$name"
|
|
|
|
# Invoke a plugin internal command to setup binaries.
|
|
mkdir -p "$out/bin"
|
|
yarn nixify install-bin $out/bin
|
|
|
|
# A package with node_modules doesn't need the cache
|
|
yarn cache clean
|
|
|
|
runHook postInstall
|
|
'';
|
|
|
|
passthru = {
|
|
inherit nodejs;
|
|
yarn-freestanding = yarn;
|
|
yarn = writeShellScriptBin "yarn" ''
|
|
exec '${yarn}/bin/yarn' --cwd '${overriddenProject}/libexec/${overriddenProject.name}' "$@"
|
|
'';
|
|
};
|
|
});
|
|
|
|
overriddenProject = optionalOverride overrideAttrs project;
|
|
|
|
cacheEntries = {
|
|
"@types/node@npm:24.13.3" = { filename = "@types-node-npm-24.13.3-b512a0bbeb-a5bc08f49b.zip"; hash = "sha512-pbwI9JuVgdzcqQ4CzXcZejx5mECAdmSULlzVFhpVPU0q6AZPfjKUQQ10jX0Ji1wYSL5/pQwG8pxBk6sWvk5Z6w=="; };
|
|
"typescript@npm:5.9.3" = { filename = "typescript-npm-5.9.3-48715be868-6bd7552ce3.zip"; hash = "sha512-a9dVLOOfl+cR21qgSPb5mVtT8cUvfYZnwavcFwDGinajCPV5zTCc5rU2Rt606aG+fIE6k7qvCijM1TajAnDhxQ=="; };
|
|
"typescript@patch:typescript@npm%3A5.9.3#optional!builtin<compat/typescript>::version=5.9.3&hash=5786d5" = { filename = "typescript-patch-6fda4d02cf-ad09fdf7a7.zip"; hash = "sha512-rQn996dWgU3OZbxgwWV7QNREUTRoWO6iMOEPLpWiidkYO24y5cEelazAzMIUtPNiidytS/GIawrbhNcR0zakMA=="; };
|
|
"undici-types@npm:7.18.2" = { filename = "undici-types-npm-7.18.2-3e6d69d829-85a7918911.zip"; hash = "sha512-haeRiRE6I4lZ16ZHNo5PfFVZw6QE69uPxEiBRc6UJvzYIlKoRKMCeY38Djfm+xeP9IHtA7xMr2NMV1fZ70NSHQ=="; };
|
|
};
|
|
|
|
in overriddenProject
|