diff --git a/devices/ellaca/hardware-config.nix b/devices/ellaca/hardware-config.nix index aeca358..570ec2a 100644 --- a/devices/ellaca/hardware-config.nix +++ b/devices/ellaca/hardware-config.nix @@ -1,8 +1,36 @@ { config, lib, ... }: { - boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "ahci" "usb_storage" "usbhid" "sd_mod" ]; - boot.initrd.kernelModules = [ ]; - boot.kernelModules = [ "kvm-amd" ]; - boot.extraModulePackages = [ ]; + boot = { + initrd = { + availableKernelModules = [ "nvme" "xhci_pci" "ahci" "usb_storage" "usbhid" "sd_mod" ]; + kernelModules = [ ]; + postDeviceCommands = lib.mkAfter '' + mkdir /btrfs_tmp + mount /dev/disk/by-uuid/b6e6bca7-1435-4b41-b174-8550eace7c32 /btrfs_tmp + if [[ -e /btrfs_tmp/root ]]; then + mkdir -p /btrfs_tmp/old_roots + timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S") + 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" + } + + for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do + delete_subvolume_recursively "$i" + done + + btrfs subvolume create /btrfs_tmp/root + umount /btrfs_tmp + ''; + }; + kernelModules = [ "kvm-amd" ]; + extraModulePackages = [ ]; + }; fileSystems = { "/boot" = { diff --git a/outputs.nix b/outputs.nix index 3aa3f1e..10a7aab 100644 --- a/outputs.nix +++ b/outputs.nix @@ -39,7 +39,7 @@ }; modules = [ ./devices/ellaca - ] ++ clientModules; + ] ++ clientModules; }; # Surface Pro 7 (i5 128GB)