From 8c5af53b9e355a2f19e87f23b1aa3a3eb62234a3 Mon Sep 17 00:00:00 2001 From: "RingOfStorms (Joshua Bell)" Date: Sat, 13 Dec 2025 17:36:19 -0600 Subject: [PATCH] more tries --- hosts/i001/hardware-mounts.nix | 89 ++++++++++++++-------------------- 1 file changed, 37 insertions(+), 52 deletions(-) diff --git a/hosts/i001/hardware-mounts.nix b/hosts/i001/hardware-mounts.nix index 77a6d9ce..f2a42e98 100644 --- a/hosts/i001/hardware-mounts.nix +++ b/hosts/i001/hardware-mounts.nix @@ -24,15 +24,15 @@ in "X-mount.subdir=@root" ]; }; - # TODO optional? - # fileSystems."/.old_roots" = { - # device = PRIMARY; - # fsType = "bcachefs"; - # options = [ - # "X-mount.mkdir" - # "X-mount.subdir=@old_roots" - # ]; - # }; + fileSystems."/.old_roots" = { + device = PRIMARY; + fsType = "bcachefs"; + options = [ + "nofail" # this may not exist yet just skip it + "X-mount.mkdir" + "X-mount.subdir=@old_roots" + ]; + }; fileSystems."/nix" = { device = PRIMARY; fsType = "bcachefs"; @@ -111,10 +111,10 @@ in "bcachefs" "vfat" ]; - # boot.initrd.extraUtilsCommands = '' - # copy_bin_and_libs ${pkgs.bcachefs-tools}/bin/bcachefs - # copy_bin_and_libs ${pkgs.keyutils}/bin/keyctl - # ''; + boot.initrd.extraUtilsCommands = '' + copy_bin_and_libs ${pkgs.bcachefs-tools}/bin/bcachefs + copy_bin_and_libs ${pkgs.keyutils}/bin/keyctl + ''; # boot.initrd.systemd.services.unlock-primary = { # description = "Unlock bcachefs root with key"; # wantedBy = [ "initrd-root-device.target" ]; @@ -167,45 +167,30 @@ in # }; boot.initrd.postResumeCommands = lib.mkAfter '' - echo "test" | bcachefs unlock ${PRIMARY} - - mkdir /primary_tmp - mount ${PRIMARY} primary_tmp/ - if [[ -e /primary_tmp/@root ]]; then - mkdir -p /primary_tmp/@old_roots - bcachefs set-file-option /primary_tmp/@old_roots --compression=zstd - - timestamp=$(date --date="@$(stat -c %Y /primary_tmp/@root)" "+%Y-%m-%-d_%H:%M:%S") - bcachefs subvolume snapshot /primary_tmp/@root "/primary_tmp/@old_roots/$timestamp" - bcachefs subvolume delete /primary_tmp/@root - fi - - for i in $(find /primary_tmp/old_roots/ -maxdepth 1 -mtime +30); do - bcachefs subvolume delete "$i" - done - - bcachefs subvolume create /primary_tmp/@root - umount /primary_tmp + keyctl link @u @s + echo "test" | bcachefs unlock -k session ${PRIMARY} ''; - # Reset root - # TODO - # boot.initrd.systemd.services.rollback-root = { - # description = "Rollback Root Filesystem to Blank Snapshot"; - # wantedBy = [ "initrd.target" ]; - # after = [ "persist.mount" ]; - # requires = [ "persist.mount" ]; - # before = [ "sysroot.mount" ]; - # unitConfig.DefaultDependencies = false; - # serviceConfig = { - # Type = "oneshot"; - # ExecStart = """ - # ${pkgs.bcachefs-tools}/bin/bcachefs subvolume snapshot @root @snapshots/root_$() - # ${pkgs.bcachefs-tools}/bin/bcachefs subvolume delete @root - # ${pkgs.bcachefs-tools}/bin/bcachefs subvolume create @root - # ${pkgs.bcachefs-tools}/bin/bcachefs unlock - # """; - # "/bin/sh -c 'bcachefs subvolume delete /persist/@root; bcachefs subvolume snapshot /persist/@root-blank /persist/@root'"; - # }; - # }; + # TODO this works for resetting root! + # boot.initrd.postResumeCommands = lib.mkAfter '' + # echo "test" | bcachefs unlock ${PRIMARY} + # + # mkdir /primary_tmp + # mount ${PRIMARY} primary_tmp/ + # if [[ -e /primary_tmp/@root ]]; then + # mkdir -p /primary_tmp/@old_roots + # bcachefs set-file-option /primary_tmp/@old_roots --compression=zstd + # + # timestamp=$(date --date="@$(stat -c %Y /primary_tmp/@root)" "+%Y-%m-%-d_%H:%M:%S") + # bcachefs subvolume snapshot /primary_tmp/@root "/primary_tmp/@old_roots/$timestamp" + # bcachefs subvolume delete /primary_tmp/@root + # fi + # + # for i in $(find /primary_tmp/old_roots/ -maxdepth 1 -mtime +30); do + # bcachefs subvolume delete "$i" + # done + # + # bcachefs subvolume create /primary_tmp/@root + # umount /primary_tmp + # ''; }