Compare commits
2 commits
a483dd3765
...
75b37cc9ec
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75b37cc9ec | ||
|
|
07c9dbb51c |
1 changed files with 16 additions and 24 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" = {
|
||||||
|
|
@ -64,8 +62,6 @@ lib.mkMerge [
|
||||||
"X-mount.mkdir"
|
"X-mount.mkdir"
|
||||||
"X-mount.subdir=@persist"
|
"X-mount.subdir=@persist"
|
||||||
];
|
];
|
||||||
# NOTE for impermanence
|
|
||||||
# neededForBoot = true;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
# SWAP (optional)
|
# SWAP (optional)
|
||||||
|
|
@ -230,23 +226,19 @@ lib.mkMerge [
|
||||||
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"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
before = [
|
||||||
|
"sysroot.mount"
|
||||||
|
];
|
||||||
wantedBy = [
|
wantedBy = [
|
||||||
"initrd-root-fs.target"
|
"initrd-root-fs.target"
|
||||||
"sysroot.mount"
|
"sysroot.mount"
|
||||||
|
|
@ -255,6 +247,7 @@ lib.mkMerge [
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
|
RemainAfterExit = true;
|
||||||
KeyringMode = "shared";
|
KeyringMode = "shared";
|
||||||
# Environment = "PATH=${
|
# Environment = "PATH=${
|
||||||
# lib.makeBinPath [
|
# lib.makeBinPath [
|
||||||
|
|
@ -265,10 +258,10 @@ lib.mkMerge [
|
||||||
|
|
||||||
script = ''
|
script = ''
|
||||||
cleanup() {
|
cleanup() {
|
||||||
# if [[ ! -e /primary_tmp/@root ]]; then
|
if [[ ! -e /primary_tmp/@root ]]; then
|
||||||
# echo "Cleanup: Creating new @root"
|
echo "Cleanup: Creating new @root"
|
||||||
# bcachefs subvolume create /primary_tmp/@root
|
bcachefs subvolume create /primary_tmp/@root
|
||||||
# fi
|
fi
|
||||||
echo "Cleanup: Unmounting /primary_tmp"
|
echo "Cleanup: Unmounting /primary_tmp"
|
||||||
umount /primary_tmp || true
|
umount /primary_tmp || true
|
||||||
}
|
}
|
||||||
|
|
@ -280,21 +273,20 @@ lib.mkMerge [
|
||||||
echo "Mounting ${PRIMARY}..."
|
echo "Mounting ${PRIMARY}..."
|
||||||
if ! mount "${PRIMARY}" /primary_tmp; then
|
if ! mount "${PRIMARY}" /primary_tmp; then
|
||||||
echo "Mount failed. Cannot reset root."
|
echo "Mount failed. Cannot reset root."
|
||||||
# TODO change to exit 1
|
exit 1
|
||||||
exit 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -e /primary_tmp/@root ]]; then
|
if [[ -e /primary_tmp/@root ]]; then
|
||||||
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 $snap"
|
||||||
|
bcachefs subvolume snapshot /primary_tmp/@root "$snap"
|
||||||
|
|
||||||
echo "Snapshotting @root to .../$timestamp"
|
echo "Deleting current @root"
|
||||||
bcachefs subvolume snapshot /primary_tmp/@root "/primary_tmp/@snapshots/old_roots/$timestamp"
|
bcachefs subvolume delete /primary_tmp/@root
|
||||||
|
|
||||||
# echo "Deleting current @root"
|
|
||||||
# bcachefs subvolume delete /primary_tmp/@root
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Trap handles creating new root and unmount
|
# Trap handles creating new root and unmount
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue