more tries
This commit is contained in:
parent
a55b2dbebd
commit
8c5af53b9e
1 changed files with 37 additions and 52 deletions
|
|
@ -24,15 +24,15 @@ in
|
||||||
"X-mount.subdir=@root"
|
"X-mount.subdir=@root"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
# TODO optional?
|
fileSystems."/.old_roots" = {
|
||||||
# fileSystems."/.old_roots" = {
|
device = PRIMARY;
|
||||||
# device = PRIMARY;
|
fsType = "bcachefs";
|
||||||
# fsType = "bcachefs";
|
options = [
|
||||||
# options = [
|
"nofail" # this may not exist yet just skip it
|
||||||
# "X-mount.mkdir"
|
"X-mount.mkdir"
|
||||||
# "X-mount.subdir=@old_roots"
|
"X-mount.subdir=@old_roots"
|
||||||
# ];
|
];
|
||||||
# };
|
};
|
||||||
fileSystems."/nix" = {
|
fileSystems."/nix" = {
|
||||||
device = PRIMARY;
|
device = PRIMARY;
|
||||||
fsType = "bcachefs";
|
fsType = "bcachefs";
|
||||||
|
|
@ -111,10 +111,10 @@ in
|
||||||
"bcachefs"
|
"bcachefs"
|
||||||
"vfat"
|
"vfat"
|
||||||
];
|
];
|
||||||
# boot.initrd.extraUtilsCommands = ''
|
boot.initrd.extraUtilsCommands = ''
|
||||||
# copy_bin_and_libs ${pkgs.bcachefs-tools}/bin/bcachefs
|
copy_bin_and_libs ${pkgs.bcachefs-tools}/bin/bcachefs
|
||||||
# copy_bin_and_libs ${pkgs.keyutils}/bin/keyctl
|
copy_bin_and_libs ${pkgs.keyutils}/bin/keyctl
|
||||||
# '';
|
'';
|
||||||
# boot.initrd.systemd.services.unlock-primary = {
|
# boot.initrd.systemd.services.unlock-primary = {
|
||||||
# description = "Unlock bcachefs root with key";
|
# description = "Unlock bcachefs root with key";
|
||||||
# wantedBy = [ "initrd-root-device.target" ];
|
# wantedBy = [ "initrd-root-device.target" ];
|
||||||
|
|
@ -167,45 +167,30 @@ in
|
||||||
# };
|
# };
|
||||||
|
|
||||||
boot.initrd.postResumeCommands = lib.mkAfter ''
|
boot.initrd.postResumeCommands = lib.mkAfter ''
|
||||||
echo "test" | bcachefs unlock ${PRIMARY}
|
keyctl link @u @s
|
||||||
|
echo "test" | bcachefs unlock -k session ${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
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Reset root
|
# TODO this works for resetting root!
|
||||||
# TODO
|
# boot.initrd.postResumeCommands = lib.mkAfter ''
|
||||||
# boot.initrd.systemd.services.rollback-root = {
|
# echo "test" | bcachefs unlock ${PRIMARY}
|
||||||
# description = "Rollback Root Filesystem to Blank Snapshot";
|
#
|
||||||
# wantedBy = [ "initrd.target" ];
|
# mkdir /primary_tmp
|
||||||
# after = [ "persist.mount" ];
|
# mount ${PRIMARY} primary_tmp/
|
||||||
# requires = [ "persist.mount" ];
|
# if [[ -e /primary_tmp/@root ]]; then
|
||||||
# before = [ "sysroot.mount" ];
|
# mkdir -p /primary_tmp/@old_roots
|
||||||
# unitConfig.DefaultDependencies = false;
|
# bcachefs set-file-option /primary_tmp/@old_roots --compression=zstd
|
||||||
# serviceConfig = {
|
#
|
||||||
# Type = "oneshot";
|
# timestamp=$(date --date="@$(stat -c %Y /primary_tmp/@root)" "+%Y-%m-%-d_%H:%M:%S")
|
||||||
# ExecStart = """
|
# bcachefs subvolume snapshot /primary_tmp/@root "/primary_tmp/@old_roots/$timestamp"
|
||||||
# ${pkgs.bcachefs-tools}/bin/bcachefs subvolume snapshot @root @snapshots/root_$()
|
# bcachefs subvolume delete /primary_tmp/@root
|
||||||
# ${pkgs.bcachefs-tools}/bin/bcachefs subvolume delete @root
|
# fi
|
||||||
# ${pkgs.bcachefs-tools}/bin/bcachefs subvolume create @root
|
#
|
||||||
# ${pkgs.bcachefs-tools}/bin/bcachefs unlock
|
# for i in $(find /primary_tmp/old_roots/ -maxdepth 1 -mtime +30); do
|
||||||
# """;
|
# bcachefs subvolume delete "$i"
|
||||||
# "/bin/sh -c 'bcachefs subvolume delete /persist/@root; bcachefs subvolume snapshot /persist/@root-blank /persist/@root'";
|
# done
|
||||||
# };
|
#
|
||||||
# };
|
# bcachefs subvolume create /primary_tmp/@root
|
||||||
|
# umount /primary_tmp
|
||||||
|
# '';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue