nix-community / npmlock2nix

nixify npm based packages [maintainer=@andir]
Apache License 2.0
130 stars 42 forks source link

Node shebang remains unpatched for some binaries #155

Open h7x4 opened 2 years ago

h7x4 commented 2 years ago

I'm working on packaging terminalizer, but I'm having some difficulties with webpack.

The issue seems to be that the node shebang doesn't get patched. After messing around in node_modules/.bin/ from --keep-failed, I also found that json5, electron and atob remains unpatched.

Some hacks I've tried is to overwrite the webpack binary with the one from nixpkgs through preInstallLinks, however it doesn't seem to want to override the existing binaries nor directories (implementation detail i guess?). I've also tried overriding the build command to use nixpkgs webpack directly, but I didn't really figure that one out. None of these hacks really seem to address the root issue though, which I guess would be "why does some binaries escape patchShebang?".

Might be the same issue as #129

Flake for debugging ```nix { description = "Record your terminal and generate animated gif images or share a web player link"; inputs = { nixpkgs.url = "nixpkgs/nixos-21.11"; flake-utils = { url = "github:numtide/flake-utils"; inputs.nixpkgs.follows = "nixpkgs"; }; npmlock2nix = { url = "github:nix-community/npmlock2nix"; flake = false; }; terminalizer-source = { url = "github:faressoft/terminalizer"; flake = false; }; }; outputs = { self, nixpkgs, npmlock2nix, flake-utils, terminalizer-source }: flake-utils.lib.eachDefaultSystem (system: let overlays = [ (self: super: { npmlock2nix = self.callPackage npmlock2nix { }; }) ]; pkgs = import nixpkgs { inherit system overlays; }; in rec { packages.default = legacyPackages.terminalizer; legacyPackages.terminalizer = pkgs.npmlock2nix.build { src = "${terminalizer-source}/"; buildInputs = with pkgs; [ # nodePackages.webpack nodejs ]; node_modules_attrs = { buildInputs = with pkgs; [ python38 nodejs ]; # preInstallLinks."webpack"."bin/webpack.js" = "${pkgs.nodePackages.webpack}/bin/webpack"; }; # buildCommands = [ "NODE_ENV=production ${pkgs.nodePackages.webpack} --optimize-minimize --progress --colors" ]; installPhase = "cp -r dist $out"; }; }); } ```
andir commented 2 years ago

What is the nodejs and npm version you are using?

h7x4 commented 2 years ago

My flake is currently pinned to nixpkgs@ccb90fb which has nodejs version 14.19.1 and npm version 6.14.16 I don't know which node/npm version was used to create the original package-lock.json

flake.lock ```json { "nodes": { "flake-utils": { "locked": { "lastModified": 1648297722, "narHash": "sha256-W+qlPsiZd8F3XkzXOzAoR+mpFqzm3ekQkJNa+PIh1BQ=", "owner": "numtide", "repo": "flake-utils", "rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade", "type": "github" }, "original": { "owner": "numtide", "repo": "flake-utils", "type": "github" } }, "nixpkgs": { "locked": { "lastModified": 1649117019, "narHash": "sha256-ID7nw/8MDgqj/cbJ0wy6AtQ9wp58hSnE6+weZwuHnso=", "owner": "NixOS", "repo": "nixpkgs", "rev": "ccb90fb9e11459aeaf83cc28d5f8910816d90dd0", "type": "github" }, "original": { "id": "nixpkgs", "ref": "nixos-21.11", "type": "indirect" } }, "npmlock2nix": { "flake": false, "locked": { "lastModified": 1648735462, "narHash": "sha256-G22WBttdFoWp7E/YvGfePOc+W+ZsQGw+IwpFbAwJNeI=", "owner": "nix-community", "repo": "npmlock2nix", "rev": "dd2897c3a6e404446704a63f40b9a29fa0acf752", "type": "github" }, "original": { "owner": "nix-community", "repo": "npmlock2nix", "type": "github" } }, "root": { "inputs": { "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", "npmlock2nix": "npmlock2nix", "terminalizer-source": "terminalizer-source" } }, "terminalizer-source": { "flake": false, "locked": { "lastModified": 1587238889, "narHash": "sha256-deYp2WCw/ur9XCO1MsOPx+qXE/MKavPxIGbNhlgPYoU=", "owner": "faressoft", "repo": "terminalizer", "rev": "fb079fc3e4a2a7e4939c65f9fe29c7fc96e1a73d", "type": "github" }, "original": { "owner": "faressoft", "repo": "terminalizer", "type": "github" } } }, "root": "root", "version": 7 } ```
h7x4 commented 2 years ago

Nevermind, I should have looked through some other issues beforehand. I see that node >= 15 is not yet supported. Maybe this could be added to the README?

infinisil commented 2 years ago

@h7x4ABk3g With #152 you should now get an error if you try to use nodejs >= 15

Regarding this issue, would #151 help? You could manually adjust the packages sources with that