Michaël Witrant
Michaël Witrant

Reputation: 7714

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.

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.

I tried running nix-shell with a modified TMPDIR environment variable but it only affects the location of the nix-shell temporary files. The nix-build files are still put in /tmp.

I also tried to export a new value for TMPDIR in the shellHook but it doesn't work.

How can I change the TMPDIR of nix-build when it's started by nix-shell?

Here's my shell.nix:

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

    shellHook = ''
    '';
  }

Upvotes: 6

Views: 2912

Answers (1)

Micha&#235;l Witrant
Micha&#235;l Witrant

Reputation: 7714

I got the answer on the NixOS forum:

If this is a mutli-user install, you need to modify the Nix daemon’s TMPDIR.

To do that on my system I created a /etc/systemd/system/nix-daemon.service.d/override.conf with:

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

Upvotes: 7

Related Questions