Change nix-build's TMPDIR from shell.nix
Asked Answered
A

1

6

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 = ''
    '';
  }
Autotruck answered 10/7, 2022 at 14:35 Comment(0)
A
7

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
Autotruck answered 11/7, 2022 at 8:54 Comment(2)
On NixOS, you'd do systemd.services.nix-daemon.environment.TMPDIR = "/var/tmp/nix-daemon";Excipient
Didn't work for me. Not sure why.Oruntha

© 2022 - 2024 — McMap. All rights reserved.