IFD-embracing Nix expression to import pnpm lock files in Nix derivations

feat: add hook

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>

+68
+52
config-hook.sh
··· 1 + # shellcheck shell=bash 2 + 3 + iplConfigHook() { 4 + echo "Executing iplConfigHook" 5 + 6 + if ! command -v "pnpm" &> /dev/null; then 7 + echo "Error: 'pnpm' binary not found in PATH. Consider adding 'pkgs.pnpm' to 'nativeBuildInputs'." >&2 8 + exit 1 9 + fi 10 + 11 + export HOME=$(mktemp -d) 12 + export npm_config_arch="@npmArch@" 13 + export npm_config_platform="@npmPlatform@" 14 + 15 + # If the packageManager field in package.json is set to a different pnpm version than what is in nixpkgs, 16 + # any pnpm command would fail in that directory, the following disables this 17 + pushd / 18 + pnpm config set manage-package-manager-versions false 19 + popd 20 + 21 + pnpm config set store-dir "$STORE_PATH" 22 + 23 + # Prevent hard linking on file systems without clone support. 24 + # See: https://pnpm.io/settings#packageimportmethod 25 + pnpm config set package-import-method clone-or-copy 26 + 27 + # mitm-cache doesn't set a full URL and pnpm defaults to https. Force it to treat it as a plain text proxy 28 + pnpm config set https-proxy "http://$https_proxy" 29 + 30 + runHook prePnpmInstall 31 + 32 + if ! pnpm install \ 33 + --ignore-scripts \ 34 + "${pnpmInstallFlags[@]}" \ 35 + --frozen-lockfile 36 + then 37 + echo 38 + echo "ERROR: pnpm failed to install dependencies" 39 + echo 40 + 41 + exit 1 42 + fi 43 + 44 + echo "Patching scripts" 45 + 46 + patchShebangs node_modules/{*,.*} 47 + 48 + echo "Finished iplConfigHook" 49 + } 50 + 51 + postConfigureHooks+=(iplConfigHook) 52 +
+1
default.nix
··· 3 3 }: 4 4 { 5 5 importPnpmLock = pkgs.callPackage ./importPnpmLock.nix { }; 6 + iplConfigHook = pkgs.callPackage ./iplConfigHook.nix { }; 6 7 }
+15
iplConfigHook.nix
··· 1 + { 2 + makeSetupHook, 3 + stdenvNoCC, 4 + mitm-cache, 5 + }: 6 + makeSetupHook { 7 + name = "import-pnpm-lock-config-hook"; 8 + propagatedBuildInputs = [ 9 + mitm-cache 10 + ]; 11 + substitutions = { 12 + npmArch = stdenvNoCC.targetPlatform.node.arch; 13 + npmPlatform = stdenvNoCC.targetPlatform.node.platform; 14 + }; 15 + } ./config-hook.sh