Booting from external thunderbolt 3/4 SSD Enclosure

Hello,

I’ve been trying to install nixos onto an external thunderbolt 3/4 SSD, and boot it from a Framework 13 AMD 7040 laptop.

The install succeeds, the thunderbolt kernel module is properly included in stage 1, but it seems like I’m missing enough stuff to add the /dev node and perhaps authorize it. The boot just sits there waiting for the /dev node to exist.

Here’s an excerpt from my configuration.nix:

  # Use the systemd-boot EFI boot loader.
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  boot.initrd.services.udev.packages = [ pkgs.bolt ];
  boot.initrd.services.udev.binPackages = [ pkgs.bolt ];
  boot.initrd.systemd.packages = [ pkgs.bolt ];
  boot.initrd.systemd.enable = true;

  services.hardware.bolt.enable = true;

I’m basically trying to replicate what the services.hardware.bolt.enable does but in stage 1 of the bootloader - to hopefully let it automatically authorize and add the /dev/nvme* node which happens properly otherwise.

I’ve gotten into the emergency shell with boot.shell_on_fail and systemd.setenv=SYSTEMD_SULOGIN_FORCE=1, and it seems to be in an odd state. The systemd unit isn’t started when the SSD is plugged in, and while find /nix/store -name "*bolt*" shows up with bolt in the store, that path doesn’t exist when I ls.

What can I do to get booting from this external thunderbolt SSD?

EDIT:
There seems to be two issues here

  1. Missing thunderbolt authorization.
    a) This can be done probably in some way similar to the above, but it seems to need /usr for boltd.
    b) This can be done with manual udev rules
boot.initrd.services.udev.rules = ''
    ACTION=="add|change", SUBSYSTEM=="thunderbolt", \
    ATTR{unique_id}=="get from udevadm --attribute-walk" \
    ATTR{authorized}="1"
'';
  1. There seems to just be a kernel or motherboard bug with this particular external ssd enclosure. Basically, the drive needs to have the power cycled for some reason - otherwise I’m hit with:
nvme nvme0: Device not ready; aborting initialisation, CSTS=0x0

I tried patching it with NVME_QUIRK_DELAY_BEFORE_CHK_RDY, even increasing the delay amount, unbinding and rebinding the nvme driver, and it seems to be basically permanent until power cycling.