numtide / devshell

Per project developer environments
https://numtide.github.io/devshell/
MIT License
1.22k stars 87 forks source link

error: collision between A and B #268

Closed deemp closed 1 year ago

deemp commented 1 year ago

Describe the bug

There happen collisions between outputs of derivations.

error: builder for '/nix/store/b26vcwkva5jibrsfgfyy0yr8a26b1xcq-devshell-dir.drv' failed with exit code 25;
       last 1 log lines:
       > error: collision between `/nix/store/wnkqs7395ycrhx4igkpk4vkpsq1j2fr7-purs-tidy-0.10.0/package.json' and `/nix/store/d85k0zkqr9d52gkd7nwvy11x562vz4ar-spago-0.93.9/package.json'
       For full logs, run 'nix log /nix/store/b26vcwkva5jibrsfgfyy0yr8a26b1xcq-devshell-dir.drv'.
error: 1 dependencies of derivation '/nix/store/i06ac43b0040qzpa3xf0gdvqqmm05dwy-devshell-env.drv' failed to build

To Reproduce

nix develop github:deemp/gists/ffd2e94d21f1939a4c55d7fa3459bc2c910f4f50?dir=purifixProject#devshell

Expected behavior

purs, spago, purs-tidy binaries are on PATH.

System information

x86_64-linux

Additional context

There are other issues mentioning the problem.

Possible solution

devShells.default = pkgs.devshell.mkShell {
  packages = pkgs.lib.lists.imap0 pkgs.lib.setPrio [
    pkgs.purs-unstable
    pkgs.spago-unstable
    pkgs.purs-tidy-unstable
  ];
};
zimbatm commented 1 year ago

The issue is that both packages have a package.json in their output, and so the merging doesn't like it.

The proper fix would be to not put the package.json in the top of the $out of the package. In general, $out should only contain folders like ./bin ./lib ... so that there are no clashes like that.

The quick fix is to wrap one of the packages with pkgs.lib.lowPrio to instruct buildEnv on which one's package.json should be linked to. Eg:

diff --git a/purifixProject/flake.nix b/purifixProject/flake.nix
index 868298a..f2677fc 100644
--- a/purifixProject/flake.nix
+++ b/purifixProject/flake.nix
@@ -38,7 +38,7 @@
           devShells.devshell = pkgs.devshell.mkShell {
             packages = [
               pkgs.purs-unstable
-              pkgs.spago-unstable
+              (pkgs.lib.lowPrio pkgs.spago-unstable)
               pkgs.purs-tidy-unstable
             ];
           };
deemp commented 1 year ago

Here's where package.json is moved to $out:

https://github.com/thomashoneyman/purescript-overlay/blob/df8b03689a92d5be94732b445206d0e4837d395f/manifests/build-support/mkSpagoDerivation.nix#L27

If not move it there, there'll be NodeJS errors when trying to execute $out/bin/spago.

UPD: NodeJS package files can be moved to $out/node_modules/package_name

like here https://github.com/thomashoneyman/purescript-overlay/pull/40