Files
nixos/hardware/filesystem.nix

64 lines
1.6 KiB
Nix
Raw Normal View History

2026-03-12 23:38:13 +00:00
{ config, lib, pkgs, modulesPath, hostname, ... }:
2026-02-22 19:54:17 +00:00
2026-03-12 23:38:13 +00:00
let
rootDisk = "/dev/disk/by-partlabel/disk-${hostname}-root";
bootDisk = "/dev/disk/by-partlabel/disk-${hostname}-ESP";
in
2026-02-27 00:51:33 +00:00
2026-03-12 23:38:13 +00:00
{
2026-02-27 00:51:33 +00:00
boot.initrd.postDeviceCommands = lib.mkAfter ''
mkdir /btrfs_tmp
2026-03-12 23:38:13 +00:00
mount ${rootDisk} /btrfs_tmp
2026-02-27 00:51:33 +00:00
if [[ -e /btrfs_tmp/root ]]; then
mkdir -p /btrfs_tmp/old_roots
2026-02-28 15:39:36 +00:00
timestamp=$(date +%Y-%m-%d_%H-%M-%S)
2026-02-27 00:51:33 +00:00
mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp"
fi
delete_subvolume_recursively() {
IFS=$'\n'
for i in $(btrfs subvolume list -o "$1" | cut -f 9 -d ' '); do
delete_subvolume_recursively "/btrfs_tmp/$i"
done
btrfs subvolume delete "$1"
}
2026-02-28 15:39:36 +00:00
for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +7); do
2026-02-27 00:51:33 +00:00
delete_subvolume_recursively "$i"
done
btrfs subvolume create /btrfs_tmp/root
umount /btrfs_tmp
'';
2026-03-12 23:38:13 +00:00
fileSystems."/" = {
device = rootDisk;
fsType = "btrfs";
options = [ "subvol=root" ];
};
2026-02-27 00:51:33 +00:00
fileSystems."/persist" = {
2026-03-12 23:38:13 +00:00
device = rootDisk;
2026-02-27 00:51:33 +00:00
neededForBoot = true;
fsType = "btrfs";
options = [ "subvol=persist" ];
};
fileSystems."/nix" = {
2026-03-12 23:38:13 +00:00
device = rootDisk;
2026-02-27 00:51:33 +00:00
neededForBoot = true;
fsType = "btrfs";
options = [ "subvol=nix" ];
2026-02-22 19:54:17 +00:00
};
2026-02-27 00:51:33 +00:00
fileSystems."/boot" = {
2026-03-12 23:38:13 +00:00
device = bootDisk;
2026-02-27 00:51:33 +00:00
fsType = "vfat";
2026-02-27 01:03:11 +00:00
options = [ "fmask=0022" "dmask=0022" "umask=0077" ];
2026-02-22 19:54:17 +00:00
};
2026-03-09 20:27:18 +00:00
swapDevices = [ {
device = "/.swapvol/swapfile";
} ];
2026-02-22 19:54:17 +00:00
}