How to redirect sandbox paths somewhere else?

I noted that Nix stores stuff being built at the moment in /tmp/nix-build-something but some builds can be pretty IO heavy and I worry to wear out my SSD, so I wanted to store the artifacts in my HD zpool. What I am looking for is a way to redirect stuff that would otherwise be saved in /tmp/nix-build-someting to /storage/builds/nix-build-something for example.

I am using NixOS btw

How can I do that?

1 Like
  systemd.tmpfiles.rules = [
    # Empty compilation dir on boot
    # To do it manually
    # sudo systemd-tmpfiles --remove --boot --prefix=/comp-temp
    "D! /comp-temp 755 root root 0"
  ];
  systemd.services.nix-daemon.environment = { TMPDIR = "/comp-temp"; };

i do multiple compilations so i move my compilation dirs from my memory to my nvme ssd

Remember to keep backups!!

2 Likes

I think I have an idea about how to structure this.

I can use systemd-tmpdir to create an empty dir in /tmp then setup a mountpoint in my PC of a dataset inside the HD, like /tmp/nix-build

That way I can replicate this setup to n future machines with this optional feature that I can setup in a per-machine basis.

I need to PoC it yet

Here is the ZFS command to setup the volume:

sudo zfs set mountpoint=/tmp/nix-build compression=off atime=off checksum=off reservation=10G sync=disabled storage/archive/nix-build

And I did a module to do the redirect:

I hope stuff don’t break later xD