Prepare, configure, and manage Firecracker microVMs in seconds!
virtualization linux microvm firecracker

feat: enhance guest network configuration for NixOS support and update Tailscale setup

+25 -6
+5 -2
crates/firecracker-vm/src/guest.rs
··· 1 1 use crate::{command::run_command, constants::BRIDGE_IP}; 2 2 use anyhow::Result; 3 3 4 - pub fn configure_guest_network(key_path: &str, guest_ip: &str) -> Result<()> { 4 + pub fn configure_guest_network(key_path: &str, guest_ip: &str, is_nixos: bool) -> Result<()> { 5 5 println!("[+] Configuring network in guest..."); 6 6 const MAX_RETRIES: u32 = 500; 7 7 let mut retries = 0; ··· 16 16 "-o", 17 17 "UserKnownHostsFile=/dev/null", 18 18 &format!("root@{}", guest_ip), 19 - &format!("echo 'nameserver {}' > /etc/resolv.conf", BRIDGE_IP), 19 + &match is_nixos { 20 + true => "uname -a".into(), 21 + false => format!("echo 'nameserver {}' > /etc/resolv.conf", BRIDGE_IP), 22 + }, 20 23 ], 21 24 false, 22 25 )
+2 -4
crates/firecracker-vm/src/lib.rs
··· 103 103 104 104 firecracker::configure(&logfile, &kernel, &rootfs, &arch, &options)?; 105 105 106 - if distro != Distro::NixOS { 107 - let guest_ip = format!("{}.firecracker", name); 108 - guest::configure_guest_network(&key_name, &guest_ip)?; 109 - } 106 + let guest_ip = format!("{}.firecracker", name); 107 + guest::configure_guest_network(&key_name, &guest_ip, distro == Distro::NixOS)?; 110 108 111 109 tailscale::setup_tailscale(&name, options)?; 112 110
+18
crates/firecracker-vm/src/tailscale.rs
··· 21 21 get_private_key_path().with_context(|| "Failed to get SSH private key path")?; 22 22 23 23 let guest_ip = format!("{}.firecracker", name); 24 + 25 + if config.nixos.unwrap_or(false) { 26 + run_ssh_command( 27 + &key_path, 28 + &guest_ip, 29 + "type tailscale || nixos-rebuild switch", 30 + )?; 31 + run_ssh_command( 32 + &key_path, 33 + &guest_ip, 34 + &format!("tailscale up --auth-key {} --hostname {}", auth_key, name), 35 + )?; 36 + run_ssh_command(&key_path, &guest_ip, "systemctl status tailscaled || true")?; 37 + run_ssh_command(&key_path, &guest_ip, "tailscale status || true")?; 38 + println!("[+] Tailscale setup completed."); 39 + return Ok(()); 40 + } 41 + 24 42 run_ssh_command(&key_path, &guest_ip, "rm -f /etc/security/namespace.init")?; 25 43 26 44 if config.alpine.unwrap_or(false) {