Nix-shell No Space Left on Device Error

Description: I’m attempting to set up a Nix-shell environment for my project. I have created a default.nix file and a requirements.txt file with the following contents:

 numpy==1.25.2
 torch==2.0.1
 torchvision==0.15.2
 matplotlib==3.7.2
 scikit-learn==1.3.0
 scipy==1.11.2
 pandas==2.1.0
 pillow==10.0.0
 argparse==1.4.0

However, when I attempt to create the Nix-shell environment, I encounter a No Space left on device error

NixOS system:

 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.49, NixOS, 23.11 (Tapir), 23.11pre521245.aa8aa7e2ea35`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.17.0`
 - channels(sukhman): `"home-manager, nixpkgs-unstable"`
 - channels(root): `"home-manager, nixos"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

You simply lack free disk space on the partition where /nix is stored.

I have already confirmed I have enough space /nix or /tmp

Did you mean /tmp? Nix is building derivations in this directory, especially with CUDA related packages, it must be quite big to hold this.

I solved it by specifying /home/user/tmp in default.nix file:

 TMPDIR=/home/sukhman/tmp/ python3 -m pip install -r requirements.txt

Here is complete default.nix file:

with import <nixpkgs> { };

let
  pythonPackages = python3Packages;
in pkgs.mkShell rec {
  name = "impurePythonEnv";
  venvDir = "./.venv";
  buildInputs = [
    # A Python interpreter including the 'venv' module is required to bootstrap
    # the environment.
    pythonPackages.python

    # This executes some shell code to initialize a venv in $venvDir before
    # dropping into the shell
    pythonPackages.venvShellHook

    # Those are dependencies that we would like to use from nixpkgs, which will
    # add them to PYTHONPATH and thus make them accessible from within the venv.
    pythonPackages.numpy
    pythonPackages.requests

    # In this particular example, in order to compile any binary extensions they may
    # require, the Python modules listed in the hypothetical requirements.txt need
    # the following packages to be installed locally:
    taglib
    openssl
    git
    libxml2
    libxslt
    libzip
    zlib
  ];

  # Run this command, only after creating the virtual environment
  postVenvCreation = ''
    unset SOURCE_DATE_EPOCH
    TMPDIR=/home/sukhman/tmp/ python3 -m pip install -r requirements.txt
  '';

  # Now we can execute any commands within the virtual environment.
  # This is optional and can be left out to run pip manually.
  postShellHook = ''
    # allow pip to install wheels
    unset SOURCE_DATE_EPOCH
  '';

}
1 Like