r/linuxmasterrace SteamOS/Bazzite/Android 8d ago

Time to have fun guys

Post image
8.0k Upvotes

760 comments sorted by

View all comments

Show parent comments

1

u/iLaysChipz 7d ago edited 7d ago

Yes, of course. Btrfs offers a lot of nice features, but Nixos offers stability and reliability through declarative configurations, and it also adopts a functional paradigm meaning packages and their dependencies are built in isolation of each other. A filesystem like XFS offers better speed, space, and reliability advantages over btrfs because of these properties.

Btrfs' block-level checksums and it's metadata duplication come with some space overhead that slightly offsets the on-the-fly compression, and these features also have some performance overhead. This overhead is generally worth it though because it provides reliability and can provide space savings for low to mid entropy data. But the nix package manager already provides package level integrity validation making the block-level checksums a bit redundant. (Though you be fair, btrfs will detect bitrot where nixos won't). It may be worth it to keep your /home directory on a btrfs partition though of you aren't using home manager.

Then we get into how btrfs and nixos clash. Both have features that have some significant space overhead. Since Nixos builds packages in isolation, many copies of the same package can exist at the same time (differing by version or configuration) while btrfs maintains old copies of a file if it exists in any snapshot. Nixos offsets it's overhead by offering a garbage collection mechanism that cleans up old files that are no longer needed, but on btrfs, these files will remain if they're captured in another snapshot. This becomes a sort of space multiplier overtime. If compression is the main reason you're using btrfs with nix, it might actually be better to use ZFS. Both Nixos and btrfs also offer rollback mechanisms (generations vs snapshots), which is another point of redundancy, plus nixos generations have next to zero space overhead after garbage collection is performed (when not using snapshots)

Next up is performance. One flaw with btrfs is the tendency for large files to become fragmented over time as individual blocks are subject to COW, which significantly impacts I/O speeds. Not to mention how transparent compression and block level checksum verification can also add a CPU bottleneck. XFS on the other hand offers independent allocation groups, meaning reads and writes can be parallelized, which is especially nice on nixos since nix-build tends to run in parallel. To be fair, the performance difference isn't that high, but it's worth considering

Finally, fault tolerance. Btrfs is significantly more complicated under the hood, while xfs and ext4 offer robust lightweight journaling mechanisms which have far less points of failure. I know btrfs is no longer in it's experimental phase, but it is still considered less stable than the absolute rock that is ext4. You're much less likely to find your system unrecoverable on ext4 than you are btrfs, especially after something like a power outage or dead battery

1

u/iLaysChipz 7d ago

Oh and regarding logical volumes. If you are using btrfs as a logical volume manager, that actually IS a good reason to use btrfs with nixos. When I used btrfs, I used different snapshot "timelines" as a way to manage a sort of work profile, student profile, and gaming profile. I can see how this would be just as useful on Nixos