svanderburg / node2nix

Generate Nix expressions to build NPM packages
MIT License
527 stars 100 forks source link

Replace nix-gitignore as it leads to unnecessary rebuilds #301

Open dbaynard opened 2 years ago

dbaynard commented 2 years ago

The unnecessary rebuilds make development work excruciating; it takes over 5 minutes to unpack and build the 1600 dependencies of one tool on my machine.

The node-packages.nix file that is generated uses nix-gitignore.gitignoreSourcePure, which uses builtins.filterSource. As Built-in Functions in the nix manual points out, filterSource should not be called on store paths, but that is exactly what gitignoreSourcePure does, here (I suspect this might be a change with flakes; it's certainly a fragility).

There are alternative options explored in https://discourse.nixos.org/t/filtering-source-trees-with-nix-and-nixpkgs/19148; I dislike the favoured one as it uses IFD, which is unnecessary.

In an override file, I was able to call override on the nodeDependencies attr (using the args attr, too),

  # Note that `overrideAttrs` _doesn't_ work, here.
  nodeDependencies = nodeDependencies.override (overrides // {
    # Overriding the derivation produced by buildNodeDependencies

    src = nodeDependencies.src.overrideAttrs (old: {
      # Overriding the mkDerivation call in that override

      src = builtins.path {
        name = old.name + "-src";
        path = args.src;
        filter = f: _: builtins.elem (builtins.baseNameOf f) [
          "package.json"
          "package-lock.json"
        ];
      };
    });
  });

This should be ok, as far as I can tell, but I have not thoroughly explored the difference, hence why I've opened an issue rather than a PR.