haskell.nix icon indicating copy to clipboard operation
haskell.nix copied to clipboard

shellFor: creates duplicate `buildInputs` on large projects, exceeding argument length limits

Open JackKelly-Bellroy opened this issue 3 years ago • 2 comments

I work on a medium-sized haskell monorepo (~40KLOC spread over 30 packages), and discovered that adding a dependency that already existed caused nix-shell and nix develop -f . to begin failing with "argument list too long" when trying to execute bash.

I checked the (list) length of buildInputs on the derivation returned by shellFor, and it had 1699 entries, many of them repeated. As a workaround I have been able to bring the list back down to its 134 unique entries:

shell.overrideAttrs (oldAttrs: {
  buildInputs = pkgs.lib.unique oldAttrs.buildInputs;
})

However lib.unique is an O(n^2) operation. While it doesn't seem to be adversely affecting our evaluation time, perhaps there's a better long-term solution.

JackKelly-Bellroy avatar Nov 18 '21 06:11 JackKelly-Bellroy

Suggestions from Nix upstream:

  • Use __structuredAttrs = true;, as Nix >= 2.4 can handle that (and possibly Nix 2.3 too).
  • Use listToAttrs to dedup the list in a faster way:
dedupByStringKey = keyFun: list:
  lib.attrValues (lib.listToAttrs (map (item: { name = keyFun item; value = item; }) list))

JackKelly-Bellroy avatar Nov 22 '21 22:11 JackKelly-Bellroy

Attempt at using __structuredAttrs: https://github.com/peterbecich/haskell.nix/commit/dc4a3eb9d9ac52564e647a821be404c77307f368

The test suite fails:

% ./test/tests.sh ghc8107
...
default-builder.sh: line 1: /setup: No such file or directory

Could this be caused by an undefined $out? https://github.com/NixOS/nix/issues/3525#issuecomment-617746049

peterbecich avatar May 09 '22 00:05 peterbecich

Consider closing this since #1613 has been merged?

avieth avatar Sep 01 '22 14:09 avieth

Yes, thanks!

michaelpj avatar Sep 01 '22 14:09 michaelpj