nix-shell 错误 - mkdir:无法创建目录“/nix/store/...”:只读文件系统

dan*_*bst 5 nixos

我正在nix-shell用来调试我的包。配置脚本如下所示:

configurePhase = ''
  mkdir -p $out
  ...
'';
Run Code Online (Sandbox Code Playgroud)

运行 via 时nix-build,此代码没问题,但是运行时nix-shell我无法$out在运行时创建目录configurePhase

mkdir: cannot create directory '/nix/store/...': Read-only file system
Run Code Online (Sandbox Code Playgroud)

我明白为什么会发生这种情况,但如何解决这个问题?

dan*_*bst 5

发生这种情况是因为$out指向/nix/store/...which 安装为只读。

正如Eelco Dolstra 指出的那样,有两种方法可以解决这个问题:

  • 不要$out在 in 中创建configurePhase,而是在 in 中进行installPhase

  • 设置$out为一些不同的值。

您可以设置$out变量

nix-shell --command "export out=/tmp/foo; return"
Run Code Online (Sandbox Code Playgroud)