From 17f56d8f4716dc22144e871cf5beb42c5f33323f Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Wed, 13 Oct 2021 16:02:06 -0600 Subject: [PATCH 1/3] Patch shebangs in dependencies --- default.nix | 2 +- nix/node-env.nix | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/default.nix b/default.nix index d01013d..3b87632 100644 --- a/default.nix +++ b/default.nix @@ -6,7 +6,7 @@ let nodeEnv = import ./nix/node-env.nix { - inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript; + inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript jq; inherit pkgs nodejs; libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null; }; diff --git a/nix/node-env.nix b/nix/node-env.nix index 219050b..e021486 100644 --- a/nix/node-env.nix +++ b/nix/node-env.nix @@ -1,6 +1,6 @@ # This file originates from node2nix -{lib, stdenv, nodejs, python2, pkgs, libtool, runCommand, writeTextFile, writeShellScript}: +{lib, stdenv, nodejs, python2, pkgs, libtool, runCommand, writeTextFile, writeShellScript, jq}: let # Workaround to cope with utillinux in Nixpkgs 20.09 and util-linux in Nixpkgs master @@ -84,6 +84,16 @@ let # Change to the package directory to install dependencies cd "$DIR/$packageName" + + # Patch shebangs in any binary files + if [ -f package.json ]; then + set +e + for file in $(cat package.json | ${jq}/bin/jq '((.bin // {}) | if type=="string" then [.] else (. | values) end) | .[]' -r); do + chmod u+x "$file" + patchShebangs "$file" + done + set -e + fi } ''; From 964975bf141dc529da94f7466f9cc1e2231dbb7c Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Wed, 13 Oct 2021 16:29:55 -0600 Subject: [PATCH 2/3] Add one more arg --- lib/expressions/CompositionExpression.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/expressions/CompositionExpression.js b/lib/expressions/CompositionExpression.js index 474ff0d..6f133ca 100644 --- a/lib/expressions/CompositionExpression.js +++ b/lib/expressions/CompositionExpression.js @@ -129,6 +129,7 @@ CompositionExpression.prototype.toNixAST = function() { runCommand: new nijs.NixInherit("pkgs"), writeTextFile: new nijs.NixInherit("pkgs"), writeShellScript: new nijs.NixInherit("pkgs"), + jq: new nijs.NixInherit("pkgs"), pkgs: new nijs.NixInherit(), nodejs: new nijs.NixInherit() } From 705317b836f950d6bde7a06cd82dd7d0c1bcd60c Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Wed, 13 Oct 2021 16:51:40 -0600 Subject: [PATCH 3/3] Expose preRebuild hook in buildNodeDependencies --- nix/node-env.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nix/node-env.nix b/nix/node-env.nix index e021486..e44a536 100644 --- a/nix/node-env.nix +++ b/nix/node-env.nix @@ -493,6 +493,7 @@ let , dontNpmInstall ? false , bypassCache ? false , reconstructLock ? false + , preRebuild ? "" , dontStrip ? true , unpackPhase ? "true" , buildPhase ? "true" @@ -510,7 +511,7 @@ let ++ buildInputs; inherit dontStrip; # Stripping may fail a build for some package deployments - inherit dontNpmInstall unpackPhase buildPhase; + inherit dontNpmInstall preRebuild unpackPhase buildPhase; includeScript = includeDependencies { inherit dependencies; }; pinpointDependenciesScript = pinpointDependenciesOfPackage args;