How to have a derivation not clash with derived environment in Nix?

646 Views Asked by At

I get the following collision error when attempting to build an environment that, as far as I can see, shouldn't have a collision (in this case, scala-env depends on ideaLocal, so it shouldn't conflict with it):

...
idea-IU-172.4155.36/bin/libyjpagent-linux.so
idea-IU-172.4155.36/bin/libyjpagent-linux64.so
idea-IU-172.4155.36/help/ideahelp.jar
idea-IU-172.4155.36/lib/libpty/linux/x86/libpty.so
idea-IU-172.4155.36/lib/libpty/linux/x86_64/libpty.so
idea-IU-172.4155.36/bin/format.sh
idea-IU-172.4155.36/bin/fsnotifier
idea-IU-172.4155.36/bin/fsnotifier-arm
idea-IU-172.4155.36/bin/fsnotifier64
idea-IU-172.4155.36/bin/idea.sh
idea-IU-172.4155.36/bin/inspect.sh
idea-IU-172.4155.36/bin/printenv.py
idea-IU-172.4155.36/bin/restart.py
building path(s) ‘/nix/store/29g92lnpi0kywy9x7vcgl9yivwa2blm6-scala-env’
created 696 symlinks in user environment
building path(s) ‘/nix/store/qrnbff8nhpmxlzkmv508aymz5razbhgf-user-environment’
Wide character in die at /nix/store/64jc9gd2rkbgdb4yjx3nrgc91bpjj5ky-buildenv.pl line 79.
collision between ‘/nix/store/75sz9nklqmrmzxvf0faxmf6zamgaznfv-idea-local/bin/idea’ and ‘/nix/store/29g92lnpi0kywy9x7vcgl9yivwa2blm6-scala-env/bin/idea’; use ‘nix-env --set-flag priority NUMBER PKGNAME’ to change the priority of one of the conflicting packages
builder for ‘/nix/store/8hp5kdicxy9i02fa07vx85p1gvh4i1bq-user-environment.drv’ failed with exit code 255
error: build of ‘/nix/store/8hp5kdicxy9i02fa07vx85p1gvh4i1bq-user-environment.drv’ failed

Here is the nix expression (most of which can be ignored, but it isn't too long so I'll paste the whole thing):

with import <nixpkgs> { };
let
  ideaLocal = stdenv.mkDerivation {
    name = "idea-local";
    buildInputs =  [ ];
    builder = builtins.toFile "builder.sh" ''
      source $stdenv/setup
      mkdir -p $out/bin
      tar zxvf $src -C $out/
      ln -sf $out/idea-IU* $out/idea
      ln -sf $out/idea/bin/idea.sh $out/bin/idea
    '';
    shellHook = ''
      IDEA_JDK=/usr/lib/jvm/zulu-8-amd64
    '';
    src = fetchurl {
      url = https://download.jetbrains.com/idea/ideaIU-2017.2.4-no-jdk.tar.gz;
      sha256 = "15a4799ffde294d0f2fce0b735bbfe370e3d0327380a0efc45905241729898e3";
    };
    priority = 5;
  };
in
buildEnv {
  name = "scala-env";                                                                                                                                                                                                                                                                                                                                                        
  paths = [                                                                                                                                                                                                                                                                                                                                                                  
    ammonite                                                                                                                                                                                                                                                                                                                                                                 
    boehmgc
    clang
    dbus # needed non-explicitly by vscode
    emacs
    git
    # idea.idea-ultimate # disabled temporarily
    ideaLocal
    less
    libunwind
    openjdk
    openssh
    re2
    rsync
    sbt
    stdenv
    syncthing # for syncrhonizing data between containers
    tmux
    unzip
    vscode
    zlib
  ];
  # builder = builtins.toFile "builder.sh" ''
  #   source $stdenv/setup
  #   mkdir -p $out
  #   echo "" > $out/Done
  #   echo "Done setting up Scala environment."
  # '';
  buildInputs = [ makeWrapper ];                                                                                                                                                                                                                                                                                                                                             
  # TODO: better filter, use ammonite script?:
  postBuild = ''
  for f in $(ls -d $out/bin/* | grep "idea"); do
    sed -i '/IDEA_JDK/d' $f
    wrapProgram $f \
      --set IDEA_JDK "/usr/lib/jvm/zulu-8-amd64" \
      --set CLANG_PATH "${clang}/bin/clang" \
      --set CLANCPP_PATH "${clang}/bin/clang++"
    done
  '';

}

Edit:

(DevContainer)which idea
/home/brandon/.nix-profile/bin/idea
(DevContainer)ls -last /home/brandon/.nix-profile/bin/idea
4 lrwxrwxrwx 1 brandon brandon 63 Jan  1  1970 /home/brandon/.nix-profile/bin/idea -> /nix/store/75sz9nklqmrmzxvf0faxmf6zamgaznfv-idea-local/bin/idea

So it looks like ideaLocal is being imported as an environment - what's the right way to just have it installed as a package that is a dependency of scalaEnv?

1

There are 1 best solutions below

0
On

Apparently the solution was to specify the profile, which I think of as the name of the environment, so that both environments aren't installed simultaneously:

nix-env -if scala-default.nix -p scala-env