retry auto unlock

This commit is contained in:
RingOfStorms (Joshua Bell) 2025-12-13 17:09:23 -06:00
parent ae8971ccf9
commit 8c53121532

View file

@ -28,6 +28,7 @@ in
device = PRIMARY; device = PRIMARY;
fsType = "bcachefs"; fsType = "bcachefs";
options = [ options = [
"X-mount.mkdir"
"X-mount.subdir=@nix" "X-mount.subdir=@nix"
"relatime" "relatime"
]; ];
@ -36,6 +37,7 @@ in
device = PRIMARY; device = PRIMARY;
fsType = "bcachefs"; fsType = "bcachefs";
options = [ options = [
"X-mount.mkdir"
"X-mount.subdir=@root" "X-mount.subdir=@root"
"relatime" "relatime"
]; ];
@ -44,6 +46,7 @@ in
device = PRIMARY; device = PRIMARY;
fsType = "bcachefs"; fsType = "bcachefs";
options = [ options = [
"X-mount.mkdir"
"X-mount.subdir=@swap" "X-mount.subdir=@swap"
"noatime" "noatime"
]; ];
@ -53,16 +56,17 @@ in
device = PRIMARY; device = PRIMARY;
fsType = "bcachefs"; fsType = "bcachefs";
options = [ options = [
"X-mount.mkdir"
"X-mount.subdir=@persist" "X-mount.subdir=@persist"
]; ];
}; };
# SWAP # SWAP
swapDevices = [ swapDevices = [
{ # {
device = "/.swap/swapfile"; # device = "/.swap/swapfile";
size = 8 * 1024; # Creates an 8GB swap file # size = 8 * 1024; # Creates an 8GB swap file
} # }
]; ];
# PRIMARY unencrypt # PRIMARY unencrypt
@ -98,6 +102,10 @@ in
"bcachefs" "bcachefs"
"vfat" "vfat"
]; ];
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 = { 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" ];
@ -108,9 +116,21 @@ in
# Wait for USB disk; you can refine this with udev-based Wants=/Requires= # Wait for USB disk; you can refine this with udev-based Wants=/Requires=
ExecStart = pkgs.writeShellScript "bcachefs-unlock-initrd" '' ExecStart = pkgs.writeShellScript "bcachefs-unlock-initrd" ''
set -eu set -eu
${pkgs.keyutils}/bin/keyctl link @u @s
echo "test" | ${pkgs.bcachefs-tools}/bin/bcachefs unlock ${PRIMARY} echo "test" | ${pkgs.bcachefs-tools}/bin/bcachefs unlock ${PRIMARY}
exit 0 exit 0
'';
};
};
# boot.initrd.systemd.services.unlock-primary = {
# description = "Unlock bcachefs root with key";
# wantedBy = [ "initrd-root-device.target" ];
# before = [ "initrd-root-device.target" ];
# unitConfig.DefaultDependencies = "no";
# serviceConfig = {
# Type = "oneshot";
# # Wait for USB disk; you can refine this with udev-based Wants=/Requires=
# ExecStart = pkgs.writeShellScript "bcachefs-unlock-initrd" ''
# echo "Waiting for USB key with label SECRETKEY..." # echo "Waiting for USB key with label SECRETKEY..."
# for i in $(seq 1 20); do # for i in $(seq 1 20); do
# if [ -e /dev/disk/by-label/SECRETKEY ]; then # if [ -e /dev/disk/by-label/SECRETKEY ]; then
@ -133,9 +153,9 @@ in
# /dev/disk/by-uuid/YOUR_BCACHEFS_UUID # /dev/disk/by-uuid/YOUR_BCACHEFS_UUID
# #
# umount /mnt-key # umount /mnt-key
''; # '';
}; # };
}; # };
# Reset root # Reset root
# TODO # TODO