I’ve been reading some articles regarding impermanence in NixOS, particularly this, this, this, and this, and I want to set up impermanence on my desktop system. Since it involves deleting my entire root, however, I figured I’d ask for advice here to learn what the best practices are for doing this to minimise risk of data loss, though it isn’t too critical since it’s a new setup. For reference, I have a Flake + home-manager setup on ZFS root, though I didn’t think to do a snapshot when the disk was empty since I didn’t know about impermanence when I started out. I also have separate ZFS datasets for /, /home, /nix, /var, and /var/lib. I want to set up impermanence for both root and home, with some persistent directories on home, but I’m not sure if I should set it up on both at once or if I should do root first and then home. Any advice or help is appreciated!

  • colin@lemmy.uninsane.org
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    i migrated from a stock nixos deployment to an amnesiac one, without creating a totally new filesystem/install (i.e. without “deleting my entire root”). right now you have a fs mounted to /. after impermanence, you’ll mount that fs to /nix and bind-mount things from /nix/persist back to parts of the rootfs. if you can access the fs offline, then you can move /nix/* up to the root of that fs, mount it at /nix instead of / during boot, and now your system’s amnesiac. all your old state will be in /nix/… instead of where anything might expect it. move that to /nix/persist, and then start adding impermanence entries for the state you want to persist.

    you can actually do this online if you’re careful (cp /nix/* up to /, then edit the fileSystems entry so that your media is mounted at /nix, nixos-rebuild switch, cp again to make sure the new generation is in both places, reboot, delete the old store which should be visible at /nix/nix/store, then organize the persisted data as above).

    safety tips are:

    • don’t delete any files until you’re sure they’re not needed.
    • if you’re okay working offline, then prefer mving stuff into where it’s supposed to be and just undoing that if it doesn’t boot.
    • if you have to work online, then don’t move anything but copy it instead, and you’ll always be able to reboot into older, known-good generations (assuming /boot is on its own fs).
    • take notes about where you mv stuff so that you know how to undo things if you go wrong.
    • join us in the #impermanence:nixos.org Matrix channel if you’re not already there :)
    • ruinationOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      Oh nice, I didn’t realise there’s an entire Matrix channel for that, I’ll join in a bit then. I’m assuming by “working offline” you mean booting into a live USB? Also, is that what the Impermanence repository does on the nix-community?

      • colin@lemmy.uninsane.org
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        I’m assuming by “working offline” you mean booting into a live USB

        yeah, that’s one way. more generally, “offline” = any setup where the filesystem(s) you’re modifying to be impermanent isn’t critical to running whatever shell/session you’re using to do the work. that lets you do things in any order so long as the end state’s bootable, whereas moving /nix/store on a live system can totally just crash it and leave it unbootable if you’re not careful.

        Also, is that what the Impermanence repository does on the nix-community?

        default behavior for that impermanence repo is that persisted directories are mounted as bind mounts and persisted files are symlinks. that was chosen mostly to maximize out-of-the-box compatibility with most software out there, i believe. most people mount some fs to /nix during early boot, and place their persisted data in the persist/ subdirectory of that mount. but there’s a hundred different ways to do it: the other most common way is to use subvolumes and snapshots (btrfs, but maybe zfs can do it too?): / is one subvolume, and you take a snapshot where it’s empty; /nix is a subvolume where everything gets persisted. the Impermanence config that mounts stuff from /nix/persist into where you want it looks the same as it does with a tmpfs-on-root setup, and you get impermanence by just reverting / to that original snapshot on every boot.

        • ruinationOP
          link
          fedilink
          English
          arrow-up
          1
          ·
          edit-2
          1 year ago

          Yeah, ZFS can do it too, in fact I think that’s what Graham used in “Erase your darlings”. I’m thinking of just going the tmpfs root route, making a new dataset for /persist, and copying over the necessary files from my original root dataset, and using the impermanence module to take care of the rest of the work. That way, if I miss some files, I can just go back and copy them over from the root dataset to the persist dataset, and once I’m sure I got everything, I can just destroy the old root dataset. Would that be a good way to go about it?