简体   繁体   English

从 shell.nix 更改 nix-build 的 TMPDIR

[英]Change nix-build's TMPDIR from shell.nix

I'm trying to use nix-shell with a shell.nix file to get a clean development environment but I don't know how to change the location of the temporary build directories.我正在尝试使用带有shell.nix文件的nix-shell来获得一个干净的开发环境,但我不知道如何更改临时构建目录的位置。

The buildInputs packages are built in /tmp but this path doesn't have enough space and I get an error: [Errno 28] No space left on device during the build. buildInputs包是在/tmp中构建的,但是这个路径没有足够的空间,我收到一个error: [Errno 28] No space left on device

I tried running nix-shell with a modified TMPDIR environment variable but it only affects the location of the nix-shell temporary files.我尝试使用修改后的TMPDIR环境变量运行nix-shell ,但它只影响nix-shell临时文件的位置。 The nix-build files are still put in /tmp . nix-build文件仍然放在/tmp中。

I also tried to export a new value for TMPDIR in the shellHook but it doesn't work.我还尝试在shellHook中为TMPDIR导出一个新值,但它不起作用。

How can I change the TMPDIR of nix-build when it's started by nix-shell ?nix-shell启动时,如何更改nix-buildTMPDIR

Here's my shell.nix :这是我的shell.nix

let
  pkgs = import <nixpkgs> {};
in
  pkgs.mkShell {
    name = "something";
    buildInputs = with pkgs; [
      python38
      python38Packages.pytorchWithCuda
    ];

    shellHook = ''
    '';
  }

I got the answer on the NixOS forum :在 NixOS 论坛上得到了答案:

If this is a mutli-user install, you need to modify the Nix daemon's TMPDIR.如果这是多用户安装,则需要修改 Nix 守护进程的 TMPDIR。

To do that on my system I created a /etc/systemd/system/nix-daemon.service.d/override.conf with:为此,我在我的系统上创建了一个/etc/systemd/system/nix-daemon.service.d/override.conf

[Service]
Environment=TMPDIR=/var/tmp/nix-daemon

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM