如何在Nix中使派生环境不与派生环境发生冲突?

时间:2017-09-18 22:43:29

标签: nix nixpkgs

在尝试构建一个环境时遇到以下冲突错误,据我所知,该环境不应该发生冲突(在这种情况下,scala-env依赖于ideaLocal,所以它不应该'与之发生冲突):

$userN = $_GET['user'];
$passW = $_GET['pass'];
$userlist = file ('auth.txt');

foreach ($userlist as $user) {
    $user_details = explode(':', $user);


    if (trim($user_details[0]) == $userN && trim($user_details[1]) == $passW) {
        $success = true;
        ECHO "Success <br />";
        break;
    }
    else {echo "failed <br />";}
}

这是nix表达式(大多数都可以忽略,但它不会太长,所以我会粘贴整个东西):

...
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

修改

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
  '';

}

所以看起来(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 被导入为环境 - 将它作为ideaLocal的依赖项安装的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

显然,解决方案是指定配置文件,我认为该配置文件是环境的名称,因此两个环境不能同时安装:

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