Keeping a big empty file on disk to occupy space

Why All My Servers Have an 8GB Empty File has a good idea of keeping an 8GB null file on on disk so that if the disk fills up you can delete the file and have space to do maintenance. What is a good way to doing that in NixOS?

2 Likes

I don’t see a reason you couldn’t just… do that? Make a big pointless file. (Btw, some file systems like ZFS support reservations and/or quotas that can be used for much the same purpose.)

7 Likes

I want to do this declaratively. But if I keep the file in the store I can’t delete it. What can I do instead? Also if the maintenance fix requires deploying, I don’t want the deploy to fail because it ran out of space.

I guess this could be a service that creates the file if there is enough space.

2 Likes

You can just add a command into system.activationScripts option to check if a file exist (e.g. /opt/myuselessfile) and if not, create it if there is enough space.
But I must agree with the comment above, this should be properly handled via limiting/rotating logs, setting reservations, monitoring/alerting etc. instead.

5 Likes

hmm, an interesting idea… however nix should work with per user quota’s…but there nothing like monitoring your servers constantly for diskspace issues.

the /nix/store actually reserves a chunk for diskspace, so that it can always nix-collect-garbage even if the volume with /nix/store on is full.

the saying nix-collect-garbage always seems to give me something back in emergency, last time it gave me back 70G. :slight_smile:

3 Likes