reset script
This commit is contained in:
parent
438f48ebf0
commit
07c9dbb51c
1 changed files with 10 additions and 20 deletions
|
|
@ -34,8 +34,6 @@ lib.mkMerge [
|
||||||
fsType = "bcachefs";
|
fsType = "bcachefs";
|
||||||
options = [
|
options = [
|
||||||
"X-mount.subdir=@root"
|
"X-mount.subdir=@root"
|
||||||
# "x-systemd.requires=unlock-bcachefs-custom.service"
|
|
||||||
# "x-systemd.after=unlock-bcachefs-custom.service"
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
fileSystems."/nix" = {
|
fileSystems."/nix" = {
|
||||||
|
|
@ -225,29 +223,24 @@ lib.mkMerge [
|
||||||
# TODO rotate root
|
# TODO rotate root
|
||||||
}
|
}
|
||||||
# Reset root for erase your darlings/impermanence/preservation
|
# Reset root for erase your darlings/impermanence/preservation
|
||||||
(lib.mkIf false {
|
(lib.mkIf true {
|
||||||
boot.initrd.systemd.services.bcachefs-reset-root = {
|
boot.initrd.systemd.services.bcachefs-reset-root = {
|
||||||
description = "Reset bcachefs root subvolume before pivot";
|
description = "Reset bcachefs root subvolume before pivot";
|
||||||
|
|
||||||
# We want this to run after we've ATTEMPTED to unlock,
|
|
||||||
# but strictly BEFORE the real root is mounted at /sysroot
|
|
||||||
after = [
|
after = [
|
||||||
"initrd-root-device.target"
|
"initrd-root-device.target"
|
||||||
"cryptsetup.target"
|
"cryptsetup.target"
|
||||||
"unlock-bcachefs-custom.service"
|
"unlock-bcachefs-custom.service"
|
||||||
];
|
];
|
||||||
|
|
||||||
# This is the most important part: prevent sysroot from mounting until we are done resetting it
|
|
||||||
before = [
|
|
||||||
"sysroot.mount"
|
|
||||||
];
|
|
||||||
|
|
||||||
requires = [
|
requires = [
|
||||||
primaryDeviceUnit
|
primaryDeviceUnit
|
||||||
"unlock-bcachefs-custom.service"
|
"unlock-bcachefs-custom.service"
|
||||||
];
|
];
|
||||||
wantedBy = [
|
|
||||||
|
|
||||||
|
before = [
|
||||||
|
"sysroot.mount"
|
||||||
|
];
|
||||||
|
wantedBy = [
|
||||||
"initrd-root-fs.target"
|
"initrd-root-fs.target"
|
||||||
"sysroot.mount"
|
"sysroot.mount"
|
||||||
"initrd.target"
|
"initrd.target"
|
||||||
|
|
@ -255,6 +248,7 @@ lib.mkMerge [
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
|
RemainAfterExit = true;
|
||||||
KeyringMode = "shared";
|
KeyringMode = "shared";
|
||||||
# Environment = "PATH=${
|
# Environment = "PATH=${
|
||||||
# lib.makeBinPath [
|
# lib.makeBinPath [
|
||||||
|
|
@ -264,10 +258,6 @@ lib.mkMerge [
|
||||||
};
|
};
|
||||||
|
|
||||||
script = ''
|
script = ''
|
||||||
# 1. Enable Debugging
|
|
||||||
set -x
|
|
||||||
|
|
||||||
# 2. Define Cleanup Trap (Robust)
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
if [[ ! -e /primary_tmp/@root ]]; then
|
if [[ ! -e /primary_tmp/@root ]]; then
|
||||||
echo "Cleanup: Creating new @root"
|
echo "Cleanup: Creating new @root"
|
||||||
|
|
@ -291,10 +281,10 @@ lib.mkMerge [
|
||||||
mkdir -p /primary_tmp/@snapshots/old_roots
|
mkdir -p /primary_tmp/@snapshots/old_roots
|
||||||
|
|
||||||
# Use safe timestamp format (dashes instead of colons)
|
# Use safe timestamp format (dashes instead of colons)
|
||||||
timestamp=$(date --date="@$(stat -c %Y /primary_tmp/@root)" "+%Y-%m-%d_%H-%M-%S")
|
timestamp=$(date "+%Y-%m-%d_%H-%M-%S")
|
||||||
|
snap="/primary_tmp/@snapshots/old_roots/$timestamp"
|
||||||
echo "Snapshotting @root to .../$timestamp"
|
echo "Snapshotting @root to $snap"
|
||||||
bcachefs subvolume snapshot /primary_tmp/@root "/primary_tmp/@snapshots/old_roots/$timestamp"
|
bcachefs subvolume snapshot /primary_tmp/@root "$snap"
|
||||||
|
|
||||||
echo "Deleting current @root"
|
echo "Deleting current @root"
|
||||||
bcachefs subvolume delete /primary_tmp/@root
|
bcachefs subvolume delete /primary_tmp/@root
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue