more tries

This commit is contained in:
RingOfStorms (Joshua Bell) 2025-12-13 17:36:19 -06:00
parent a55b2dbebd
commit 8c5af53b9e

View file

@ -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
# '';
}