From bfdfc7ee68e4dd951e138538ecf3a1490c18ac1a Mon Sep 17 00:00:00 2001 From: clerie Date: Wed, 7 Feb 2024 18:42:30 +0100 Subject: [PATCH] hosts/zinc: custom network setup in initrd --- hosts/zinc/initrd.nix | 45 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/hosts/zinc/initrd.nix b/hosts/zinc/initrd.nix index fa69543..bd00129 100644 --- a/hosts/zinc/initrd.nix +++ b/hosts/zinc/initrd.nix @@ -1,6 +1,31 @@ -{ config, ... }: +{ config, pkgs, lib, ... }: -{ +with lib; + +let + + configure_network = pkgs.writeScriptBin "configure-network" '' + ifdisplay="" + while true; do + ifdisplay_new=$(ipconfig -t 10 all) + ipconfig_status=$? + + # Only show network config if something changes + if [[ "$ifdisplay" != "$ifdisplay_new" ]]; then + ifdisplay=$ifdisplay_new + echo + echo "$ifdisplay" + echo + fi + + # Wait a little before checking again + if [[ $ipconfig_status == 0 ]]; then + sleep 5 + fi + done + ''; + +in { boot.initrd.network.enable = true; boot.initrd.network.ssh = { @@ -16,7 +41,21 @@ "igc" # integrated rj45 network interface "cdc_ether" # external 5G modem via usb ]; - boot.kernelParams = [ "ip=dhcp" ]; + + boot.initrd.extraUtilsCommands = '' + copy_bin_and_libs ${configure_network}/bin/configure-network + ''; + + boot.initrd.network.postCommands = mkBefore '' + configure-network & + ''; + + boot.initrd.postMountCommands = mkBefore '' + pkill -x configure-network + + # Override the previously set interfaces with the ones that really exist + ifaces=$(ip -o link show | grep "link/ether" | cut -d: -f2 | xargs -n 1) + ''; boot.initrd.network.wireguard = { enable = true;