Recently, I encountered a “No space left on device” error while trying to install IntelliJ on my NixOS system. Despite having 70 GB of available space, the issue persisted. As a newcomer to NixOS, dual-booting with Windows, I was puzzled by this problem.
Understanding the Issue: The error wasn’t due to a lack of total disk space but was likely related to the temporary directory (/tmp) or the Nix store (/nix/store) running out of space. This is a common issue in NixOS, especially with large package installations. I suspected the Nix store was full, so I tried the following commands to free up space:
nix store --optimizenix store --gc
Unfortunately, these didn’t resolve the issue. I turned to Reddit and other online resources, hoping to find others who faced similar issues. However, documentation was sparse, and solutions were not clearly explained. Solutions Tried: Here are some options I explored:
-
Checking /tmp Directory: Ensured it wasn’t full.
-
Increasing Nix Store Size: Considered adjusting the Nix store size.
-
Clearing Cache: Attempted to clear any unnecessary cache files.
-
Increase the tmpfs size: You can try increasing the tmpfs size by adding the following line to your
/etc/nixos/configuration.nixfile:
boot.runSize = "10G"; # adjust the size as neededThen, restart your system and try installing the package again.
-
Use a larger swap partition: If you have a swap partition, ensure it’s large enough to accommodate the temporary build process. You can check the current swap size using
swapon -s. -
Mount the Nix store with a larger size: You can remount the Nix store with a larger size using the following command:
mount -o remount,size=10G,noatime /nix/.rw-storeAdjust the size as needed.
- Clear temporary files: Try clearing temporary files and directories, including
/tmpand/var/tmp, to free up space.
None of those solution seem to solve the problem i was having each time i build a package I keep getting the no space left on device error. Then i came across a blog post that solve the issue i was having. Solutions Explored:
- Increase tmpfs Size:
- Explanation: tmpfs stores files in volatile memory. Increasing its size allows more files to be stored in memory.
- How to Apply:
- Add the following line to
/etc/nixos/configuration.nix:boot.tmpfsSize = "4G"; # Adjust this size as needed - Apply the changes with:
Terminal window sudo nixos-rebuild switch
- Add the following line to
- Consideration: Ensure enough free RAM or swap to support the increased size.
- Increase Swap Space:
- Explanation: Swap space acts as overflow memory when RAM is full, supporting resource-heavy operations.
- Check Temporary File Storage:
-
Use the following command to check current tmpfs usage:
Terminal window df -h | grep tmpfs -
If low, increase
/tmpsize by settingboot.tmpfsSizein the NixOS configuration. Conclusion: After adjusting the tmpfs size, the error was resolved. This experience taught me valuable lessons about managing disk space on NixOS, and I hope it helps others facing similar issues.
-