Persistent btrfs subvolume mounting

I am currently following the following guide to set up NixOS for my laptop:
https://mt-caret.github.io/blog/posts/2020-06-29-optin-state.html#fnref5
I watched Wilfrid Taylor’s youtube video on installing NixOS, and he explains that in order to have a NixOS filesystem mounting config that is persistent across installs, he uses /dev/disk/by-label to specify mounting partitions. The explanation starts at this specific time in the video:

I like the idea and was hoping to integrate that into the tutorial above, but while I could label the btrfs partition, the subvolumes, being mounted separately from each other, must be specified by uuid. Is there any way to specify these persistently?

For btrfs with subvolumes, you need to specify two things, the btrfs partition label and the subvolume name, so for instance I have something like this:

fileSystems = {
  "/" = {
    label = "nixos";
    fsType = "btrfs";
    options = [ "subvol=root" ];
  };
  "/home" = {
    label = "nixos";
    fsType = "btrfs";
    options = [ "subvol=home" ];
  };
};

And then you have the same reproducible setup, as long as you use the same partition label and subvolume names on the new system. You probably also want to add some additional btrfs mount options there.

For reference, this is my actual filesystem config: ~r-vdp/nixos-config (116803c386fee83033554aa783557857e4703184): modules/btrfs.nix - sourcehut git

1 Like

Wow, that fits perfectly! Thanks so much.