我在default.nix
中定义了以下环境:
with import <nixpkgs> {};
stdenv.mkDerivation rec {
name = "env";
env = buildEnv { name = name; paths = buildInputs; };
buildInputs = [
python35
python35Packages.pyyaml
];
}
如果我运行nix-shell
,python
仍然是/usr/bin/python
的系统python(在Ubuntu上运行),而python3
是由安装的Python 3.5二进制文件的符号链接尼克斯。有没有办法定义环境,以便python
指向Nix Python 3.5?
答案 0 :(得分:2)
您可以使用runCommand
创建仅包含python
符号链接的新派生。
with import <nixpkgs> {};
stdenv.mkDerivation rec {
name = "env";
env = buildEnv { name = name; paths = buildInputs; };
buildInputs = [
(runCommand "python-alias" {} ''
mkdir -p $out/bin
ln -s ${python35}/bin/python3 $out/bin/python
'')
python35
python35Packages.pyyaml
];
}
nix-shell --pure --run 'python --version'
Python 3.5.3
答案 1 :(得分:1)
一个简单的解决方案是向您的环境添加shell挂钩,以定义从python
到python3
的别名。只有在您运行nix-shell
:
with import <nixpkgs> {};
stdenv.mkDerivation rec {
name = "env";
env = buildEnv { name = name; paths = buildInputs; };
buildInputs = [
python35
python35Packages.pyyaml
];
# Customizable development shell setup
shellHook = ''
alias python='python3'
'';
}