!JQvnJacrwKgtkGHYHO:matrix.org

NixOS + Framework

225 Members
Discussing NixOS in the context of the Framework laptop50 Servers

Load older messages


SenderMessageTime
10 May 2026
@sudoforge:matrix.orgsudoforgewhat you're looking at was actually manually partitioned back in the day16:35:11
@albertlarsan68:albertlarsan.frAlbert LarsanHaving swap also crypted in the same luks container is the main benefit for me (ignoring swap files).16:37:10
@sudoforge:matrix.orgsudoforge well, yeah. /swap for me is just a btrfs subvolume and my swap space is a swap file conveniently at /swap/file 16:37:33
@sudoforge:matrix.orgsudoforge

disko configuration that i wrote recently but haven't used to reformat my in-use disk (because i haven't bothered migrating) is:

let
  # mkSubvolumes is a helper function to define BTRFS subvolumes from a list
  # of strings (representing the path the subvolume will be mounted at, and
  # using that as the name)
  mkSubvolumes = paths: builtins.listToAttrs (map (p: {
    name = p;
    value = {
      mountpoint = if p == "/root" then "/" else p;
      mountOptions = [ "defaults" "ssd" "compress=zstd:3" "noatime" ];
    };
  }) paths);
in
{
  disko.devices = {
    system = {
      device = "/dev/disk/by-id/...";
      type = "disk";

      content = {
        type = "gpt";

        partitions = {
          ESP = {
            size = "1024M";
            type = "EF00";
            content = {
              type = "filesystem";
              format = "vfat";
              mountpoint = "/boot";
              mountOptions = [ "umask=0077" ];
            };
          };

          luks = {
            size = "100%";
            content.type = "luks";
            content.name = "system";
            content.settings.allowDiscards = true;

            # use a fido2 key for unlocking
            content.enrollFido2 = true;

            # do not generate a recovery passphrase (i manually add additional fido keys)
            content.enrollRecovery = false;

            content.content = {
              type = "btrfs";

              subvolumes = mkSubvolumes [
                "/nix"
                "/persist"
                "/root"
                "/var/log"
                "/home"
              ] // {
                "/swap" = {
                  mountpoint = "/swap";
                  swap.swapfile.size = "72G";
                  swap.swapfile.path = "file"; # relative path, results in /swap/file
                };
              };

              # This hook creates a snapshot of the root subvolume after it is
              # created (and critically, empty), which is used for automatic
              # rollback on startup. see //system/modules:impermanence.nix for
              # more information about that process.
              postCreateHook = ''
                set -eufo pipefail
                MOUNTPOINT=$(mktemp -d)
                mount --type btrfs \
                  --options defaults,ssd,noatime,subvol=/ \
                  /dev/mapper/system \
                  "$MOUNTPOINT"
                trap 'umount "$MOUNTPOINT"; rm -rf "$MOUNTPOINT"' EXIT
                btrfs subvolume snapshot -r \
                  "$MOUNTPOINT/root" "$MOUNTPOINT/root-blank"
              '';
            };
          };
        };
      };
    };
  };
}
16:38:46
@albertlarsan68:albertlarsan.frAlbert LarsanAlso, moving stuff by adding a pv to lvm and removing the old pv is also nice (although I never used it). (you can also do this using btrfs native multi-disk support)16:39:12
@sudoforge:matrix.orgsudoforge

you can also do this using btrfs native multi-disk support

this is how i'll be migrating this machine's disk to a new disk, with the above disko configuration. btrfs send :)

16:41:08
@albertlarsan68:albertlarsan.frAlbert LarsanI have another impermanance setup, where I move the root submodule to a subfolder (for crash recovery), and delete the ones that are too old.16:42:41
@sudoforge:matrix.orgsudoforge

my impermanence module (referenced in the above config) just sets up the boot.initrd.systemd.services.rollback unit that handles deleting the root subvol and rolling back from the snapshot, and contains my environment.persistence."/persist" configuration (and other stuff necessary to handle w/ impermanence.

i'd be interested in seeing your crash recovery setup.

16:47:42
@sudoforge:matrix.orgsudoforge *

my impermanence module (referenced in the above config) just sets up the boot.initrd.systemd.services.rollback unit that handles deleting the root subvol and rolling back from the snapshot, and contains my environment.persistence."/persist" configuration, and other stuff necessary to handle w/ impermanence.

i'd be interested in seeing your crash recovery setup.

16:48:11
@sudoforge:matrix.orgsudoforge *

my impermanence module (referenced in the above config) just sets up the boot.initrd.systemd.services.rollback unit that handles deleting the root subvol and rolling back from the snapshot, contains my environment.persistence."/persist" configuration, and other stuff necessary to handle w/ impermanence.

i'd be interested in seeing your crash recovery setup.

16:48:22
@sudoforge:matrix.orgsudoforgeor do you simply mean that instead of deleting the root subvol on boot (like i do currently), you create another snapshot of it16:50:58
@albertlarsan68:albertlarsan.frAlbert Larsan I have this version (https://git.sr.ht/~albertlarsan68/dotfiles/tree/main/item/nixos/scripts/root-reset.sh) that snapshots the root before rolling it back (with a failed attempt at preserving nested subvolumes). It runs after hibernation resume and before mounting sysroot.
.The modern version (for the new machines) is at https://git.sr.ht/~albertlarsan68/dotfiles/tree/flake-parts/item/nixos-modules/impermanence/rollback.sh and literrally mvs the /root submodule to a dated folder, then deletes old versions.
16:52:53
@albertlarsan68:albertlarsan.frAlbert LarsanThe modern version does properly save nested submodules16:53:46
@sudoforge:matrix.orgsudoforgegot it16:55:18
@sudoforge:matrix.orgsudoforgei don't care about preserving the root subvol. that's the whole point of impermanence, after all :)16:55:42
@sudoforge:matrix.orgsudoforge
        btrfs subvolume delete /mnt/root

        btrfs subvolume snapshot /mnt/root-blank /mnt/root

this snippet is from the systemd unit that runs in initrd before sysroot, and just unconditionally deletes the subvol and restores it from the blank snapshot (this is taken at disk formatting time; the above disko config handles this with a postCreateHook)

16:58:38
@albertlarsan68:albertlarsan.frAlbert LarsanSaving the old snapshot saved me more than once, when my computer crashed, I could mount the old snapshot and recover some files that way.17:07:27
@albertlarsan68:albertlarsan.frAlbert LarsanThat is why I only keep the latest boot on old version and the last 1 day of boots for the modern version.17:09:33
@sudoforge:matrix.orgsudoforgemakes sense17:11:03
@rajil:rajils.comtrumee sudoforge: how do you specify the swapfile for resume? 17:29:05
@sudoforge:matrix.orgsudoforgehttps://search.nixos.org/options?channel=unstable&query=resumeDevice#show=option%253Aboot.resumeDevice17:30:20
@sudoforge:matrix.orgsudoforge

see also:

  • https://search.nixos.org/options?channel=unstable&query=postResume#show=option%253Aboot.initrd.postResumeCommands
  • https://search.nixos.org/options?channel=unstable&query=postDevice#show=option%253Aboot.initrd.postDeviceCommands
17:32:42
@rajil:rajils.comtrumeeFor a file offset is needed it seems.17:39:13
@sudoforge:matrix.orgsudoforgeyes17:42:54
@albertlarsan68:albertlarsan.frAlbert LarsanAlso why I don’t bother with swapfiles, only a swap partition17:43:49
@albertlarsan68:albertlarsan.frAlbert LarsanDon’t have to find the offset (and make sure btrfs doesn’t break the file)17:44:14
@sudoforge:matrix.orgsudoforgefor sure, a swap partition is simpler17:44:18
@sudoforge:matrix.orgsudoforge trumee since you seem newer to all of this i'm going to recommend that you use a swap partition 17:44:39
@sudoforge:matrix.orgsudoforgemake it a little bigger than the RAM you have on the machine (or the RAM you plan to have on the machine)17:50:56
@sudoforge:matrix.orgsudoforgei guess, this is where the lvm-under-luks-before-your-fs comes into play17:51:13

Show newer messages


Back to Room ListRoom Version: 10