by SkyMarshal · 3y ago · 0 comments
With / all in memory it automatically gets wiped and recreated every reboot, without needing to actively erase a disk, and thus with much less drive wear (depending on how frequently you reboot). It’s also faster on some things when loading from RAM instead of the disk. And it’s overall a cleaner, simpler setup.
https://elis.nu/blog/2020/05/nixos-tmpfs-as-root/
You can also put tmpfs on home as well, using Impermanence and Home Manager to persist things like ~/.config and whatever other files or folders need to persist between reboots:
https://elis.nu/blog/2020/06/nixos-tmpfs-as-home/
tmpfs on / is enabled by NixOS’s unique design, in which it keeps the entire system in /nix/store and then softlinks all the paths into their appropriate place in /. With tmpfs on /, NixOS automatically recreates those softlinks in tmpfs on reboot. Very little setup effort is required to make this work.
Everything that needs to be persisted for / is done so either in configuration.nix (or equivalent flake), or using Impermanence. Once you've persisted things in one of those, it will remain so for all future derivations.
You can also create separate ZFS pools for things like LXC/LXD that need to persist between boots, but don't naturally go in / or /home.
Unless you’re working on a server with a ton of ram, I also think using tmpfs is more likely to shoot yourself in the foot with excess memory pressure. I don’t know of a way for the kernel to free memory if you write a huge file to the tmpfs partition by mistake, unless you use swap, and then you have the problems that come with that.
Tmpfs might be faster though!
It defaults to 50% of physical RAM, but you can set the size option to whatever you want: https://www.kernel.org/doc/html/latest/filesystems/tmpfs.htm...
(So yes, something to consider, but totally possible to mitigate)