ZFS Imperm Bare-Metal
I couldn’t get disko to bend to my will so I wrote the following bash script. The script automates the steps in Graham Christensen’s Erase your darlings
The Storage Architecture
The script below automates the “Erase Your Darlings” setup. It organizes your data into three distinct “levels” of persistence:
-
The Volatile (
/): A ZFS dataset that is blank at boot. We take a snapshot called @blank immediately after creation. In your NixOS configuration, you will set up a boot-time script to roll back to this @blank snapshot, effectively “formatting” your root in milliseconds. -
The Store (
/nix): A separate dataset for the Nix store. This doesn’t need to be wiped because Nix already manages its own integrity. -
The Safe (
/persistand/home): These datasets hold the things you actually care about—your SSH keys, browser profiles, and project files.
What this script automates
This bash script handles the “Stage 0” heavy lifting. It will:
-
Partition your disk with an EFI boot partition and a LUKS2 encrypted container.
-
Initialize a ZFS pool (
rpool) with performance-optimized settings (likeashift=12andzstdcompression). -
Carve out the datasets required for an Impermanence setup.
-
Mount the hierarchy into
/mntsonixos-generate-configcan detect the specialized ZFS layout.
WARNING: This is a destructive operation. Running this script will wipe the target drive completely. Ensure you have backed up any existing data before proceeding.
Quick Start
- Start with the minimal ISO:
-
The script handles the partitioning, formatting, mounting, and lastly, runs
nixos-generate-config --root /mnt. After running the script, edit the files in the repo matching your user and device. Finally, after you’re sure you haven’t missed anything, runnixos-install.
export NIX_CONFIG='experimental-features = nix-command flakes'
- Clone the starter repo:
git clone https://github.com/saylesss88/my-flake2.git
- Inspect & Run the script provided with the repo & follow prompts.:
WARNING: This is a destructive operation. Running this script will wipe the target drive completely. Ensure you have backed up any existing data before proceeding.
sudo chmod +x ./install.sh
sudo bash ./install.sh
- I tested the script on an
nvme0n1drive with no issues.
- Run the following commands:
# Get your UUID#
sudo blkid /dev/YOUR_DISK > /tmp/blk.txt
# Generate a hashed password
mkpasswd -m yescrypt > /tmp/pass.txt
# Generate a rand # for `networking.hostId`
head -c4 /dev/urandom | xxd -p > /tmp/rand.txt
-
Edit
flake.nix,configuration.nix, and replace the reposhardware-configuration.nixwith your own. -
Add
neededForBootto thehomeandpersistdatasets in the generatedhardware-configuration.nix.
Example:
fileSystems."/home" = {
device = "rpool/safe/home";
fsType = "zfs";
neededForBoot = true;
};
fileSystems."/persist" = {
device = "rpool/safe/persist";
fsType = "zfs";
neededForBoot = true;
};
- Move the flake to
/mnt/etc/nixos/
sudo mv ~/my-flake2 /mnt/etc/nixos/
- Do a final check and install (change
hostto your host name)
sudo nixos-install --flake /mnt/etc/nixos/myflake2#host
- Read the comments, they let you know of requirements.
-
Reboot. I typically run
nixos-installwith the minimal requirements, reboot, and then configure my window manager/DE. -
After reboot, adjust permissions for your
$USER:
sudo mkdir -p /persist/home/$USER
# Set ownership for the persistent home directory
sudo chown -R 1000:100 /persist/home/$USER
# Ensure the home dataset itself is accessible
sudo chmod 755 /home
sudo chmod 755 /persist/home
# Test file, should be gone after reboot
sudo touch /etc/rollback-canary
-
Uncomment the import of the impermanence module in the
configuration.nix. -
Reboot, then check:
sudo ls /etc/rollback-canary
- You should get an error:
"/etc/rollback-canary": No such file or directory (os error 2)
What gets Wiped vs. What Stays
What gets wiped?:
Since we roll back (rpool/local/root):
-
/etc(including system configs) -> WIPED -
/var(logs, databases, containers) -> WIPED -
/root(the root users home directory) -> WIPED -
/usr(though in NixOS this is mostly empty) -> WIPED
What survives?:
-
/nix(mounted fromrpool/local/nix) -> PERSISTS -
/boot(mounted fromrpool/local/boot) -> PERSISTS -
/home(mounted fromrpool/safe/home) -> PERSISTS -
/persists(mounted fromrpool/safe/persist) -> PERSISTS