From b85c1e319e28161044e0ca1a33cdb69310d1e93f Mon Sep 17 00:00:00 2001 From: Lily Foster Date: Tue, 7 Mar 2023 10:20:44 -0500 Subject: [PATCH 1/2] node2nix: pull in patch to fix bin scripts with crlf line-endings This is minor fallout from svanderburg/node2nix#302 which made node2nix handle installing script bins itself (since npm stopped doing that correctly). It seems npm was doing line-ending normalization when installing these files itself, so in addition to making all bins executable we now also do a crlf to lf conversion on them if they are a script with a shebang. --- pkgs/development/node-packages/overrides.nix | 22 +++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/pkgs/development/node-packages/overrides.nix b/pkgs/development/node-packages/overrides.nix index 1ecf716329b984f..2c1fd593ea2248c 100644 --- a/pkgs/development/node-packages/overrides.nix +++ b/pkgs/development/node-packages/overrides.nix @@ -342,14 +342,22 @@ final: prev: { }; nativeBuildInputs = [ pkgs.buildPackages.makeWrapper ]; postInstall = let - # Needed to fix Node.js 16+ - PR svanderburg/node2nix#302 - npmPatch = fetchpatch { - name = "emit-lockfile-v2-and-fix-bin-links-with-npmv7.patch"; - url = "https://github.com/svanderburg/node2nix/commit/375a055041b5ee49ca5fb3f74a58ca197c90c7d5.patch"; - hash = "sha256-uVYrXptJILojeur9s2O+J/f2vyPNCaZMn1GM/NoC5n8="; - }; + patches = [ + # Needed to fix Node.js 16+ - PR svanderburg/node2nix#302 + (fetchpatch { + name = "emit-lockfile-v2-and-fix-bin-links-with-npmv7.patch"; + url = "https://github.com/svanderburg/node2nix/commit/375a055041b5ee49ca5fb3f74a58ca197c90c7d5.patch"; + hash = "sha256-uVYrXptJILojeur9s2O+J/f2vyPNCaZMn1GM/NoC5n8="; + }) + # Needed to fix packages with DOS line-endings after above patch - PR svanderburg/node2nix#314 + (fetchpatch { + name = "convert-crlf-for-script-bin-files.patch"; + url = "https://github.com/svanderburg/node2nix/commit/91aa511fe7107938b0409a02ab8c457a6de2d8ca.patch"; + hash = "sha256-ISiKYkur/o8enKDzJ8mQndkkSC4yrTNlheqyH+LiXlU="; + }) + ]; in '' - patch -d $out/lib/node_modules/node2nix -p1 < ${npmPatch} + ${lib.concatStringsSep "\n" (map (patch: "patch -d $out/lib/node_modules/node2nix -p1 < ${patch}") patches)} wrapProgram "$out/bin/node2nix" --prefix PATH : ${lib.makeBinPath [ pkgs.nix ]} ''; }; From 0835e5a189bf0ae676ccfd91afaf0e6c39c65b28 Mon Sep 17 00:00:00 2001 From: Lily Foster Date: Tue, 7 Mar 2023 10:23:11 -0500 Subject: [PATCH 2/2] nodePackages: regen only node-env --- pkgs/development/node-packages/node-env.nix | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkgs/development/node-packages/node-env.nix b/pkgs/development/node-packages/node-env.nix index 5dad9ec63d47cd2..bc1e36628ac8ae1 100644 --- a/pkgs/development/node-packages/node-env.nix +++ b/pkgs/development/node-packages/node-env.nix @@ -530,12 +530,15 @@ let then ln -s $out/lib/node_modules/.bin $out/bin - # Patch the shebang lines of all the executables + # Fixup all executables ls $out/bin/* | while read i do file="$(readlink -f "$i")" chmod u+rwx "$file" - patchShebangs "$file" + if isScript "$file" + then + sed -i 's/\r$//' "$file" # convert crlf to lf + fi done fi