Multicast DNS in boot.initrd

I want to decrypt LUKS / ZFS encrypted /root via SSH over mDNS within boot.initrd (NixOS Stage 1) (ssh hostname.local). Following DHCP in initrd · Issue #63941 · NixOS/nixpkgs · GitHub I tried the following configuration for the server:

  1. Using DHCP via udhcpc.enable
boot.initrd = {
  availableKernelModules = [ "r8169" ];
  network = {
    enable = true;
    udhcpc.enable = true;
    flushBeforeStage2 = true;
  };
};
  1. Using DHCP via kernelParams
boot.kernelParams = [ "::::none" ];
boot.initrd = {
  network = {
    enable = true;
    flushBeforeStage2 = true;
  };
};
services.resolved.enable = true;
networking.networkmanager.dns = "systemd-resolved";
  1. Using static address via kernelParams
boot.kernelParams = [ "ip=10.25.0.100::10.25.0.1:255.255.255.0:${config.networking.hostName}::none" ];
boot.initrd = {
  network = {
    enable = true;
    flushBeforeStage2 = true;
  };
};
services.resolved.enable = true;
networking.networkmanager.dns = "systemd-resolved";

I tried multiple times, and connections via IP address succeeded for 1, 2, and 3. For 3, I succeeded once via mDNS, but it hasn’t worked since then.

Could not resolve hostname hostname.local: Device or resource busy

I confirmed that mDNS works after boot process.

Adding

networking.networkmanager.connectionConfig."connection.mdns" = 2;

did not work.

I would prefer to connect using DHCP, but I’m not sure how to configure it. I would appreciate your guidance.

You need an mdns resolver in the initrd. Your best best is the systemd initrd and enabling resolved and enabling MulticastDNS on the network.