Files
nixos/hardware/filesystem.nix

67 lines
1.8 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-13 19:14:07 +00:00
# fileSystems."/" = {
# device = rootDisk;
# fsType = "btrfs";
# options = [ "subvol=root" ];
# };
#
# fileSystems."/persist" = {
# device = rootDisk;
# neededForBoot = true;
# fsType = "btrfs";
# options = [ "subvol=persist" ];
# };
#
# fileSystems."/nix" = {
# device = rootDisk;
# neededForBoot = true;
# fsType = "btrfs";
# options = [ "subvol=nix" ];
# };
#
# fileSystems."/boot" = {
# device = bootDisk;
# fsType = "vfat";
# options = [ "fmask=0022" "dmask=0022" "umask=0077" ];
# };
#
# swapDevices = [ {
# device = "/.swapvol/swapfile";
# } ];
2026-03-12 23:38:13 +00:00
2026-03-13 19:14:07 +00:00
fileSystems."/persist".neededForBoot = true;
fileSystems."/nix".neededForBoot = true;
2026-02-22 19:54:17 +00:00
}