Skip to content

Instantly share code, notes, and snippets.

@zsedem
Last active June 7, 2022 13:48
Show Gist options
  • Save zsedem/4b9ca31f07e6377873ca6f4747a13297 to your computer and use it in GitHub Desktop.
Save zsedem/4b9ca31f07e6377873ca6f4747a13297 to your computer and use it in GitHub Desktop.
NixOS with Btrfs
# I have 3 btrfs subvolume /root, /home, /nix-store and these are used as the name suggest
# Now, when i create new nixos configuration i can make a snapshot of root and home, before i switch to a new config.
CURRENT_GENERATION=`readlink /nix/var/nix/profiles/system | cut -d'-' -f2`; echo Determined current generation: $CURRENT_GENERATION
sudo mkdir -p /btrfs
# the / is not mounted in my btrfs filesystem by default, because my filesystem root is the /root subvolume
sudo mount /dev/mapper/NixOS /btrfs
sudo btrfs subvolume snapshot /btrfs/root /btrfs/root-$CURRENT_GENERATION-snapshot
# I also make a snapshot of home, because i use gnome or KDE, which contains a lots of config and cache, which can broke by a rollback.
sudo btrfs subvolume snapshot /btrfs/home /btrfs/home-$CURRENT_GENERATION-snapshot
# We can see how much space we use for the snapshots:
sudo btrfs filesystem du -s --mbytes --si /btrfs/*
# Total Exclusive Set shared Filename
# 2834.48MB 9.58MB 2504.99MB /btrfs/home
# 2833.87MB 8.65MB 2505.27MB /btrfs/home-7-snapshot
#12234.15MB 12234.15MB 0.00MB /btrfs/nix-store
# 119.43MB 2.10MB 115.00MB /btrfs/root
# 119.44MB 0.82MB 116.28MB /btrfs/root-7-snapshot
#
# So there is 12 GB that we do not have to snapshot at all and also the root snapshot itself only takes around 12 MB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment