Created
June 18, 2025 04:46
-
-
Save aabccd021/e0c381f0675f07a63e7a7dd68fb922fc to your computer and use it in GitHub Desktop.
NixOS debug vm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ lib, modulesPath, ... }: | |
{ | |
imports = [ "${modulesPath}/virtualisation/qemu-vm.nix" ]; | |
disko.devices.disk.disk1.device = lib.mkForce "/dev/vda"; | |
services.openssh.settings.PermitRootLogin = "yes"; | |
services.openssh.settings.PermitEmptyPasswords = "yes"; | |
services.openssh.settings.PasswordAuthentication = lib.mkForce true; | |
users.users.root.password = ""; | |
security.pam.services.sshd.allowNullPassword = true; | |
# Use tmpfs as filesystem. | |
# All data will be deleted when vm shuts down. | |
# Remove this option or set path as value if you want vm storage to persist across reboots. | |
virtualisation.diskImage = null; | |
virtualisation.forwardPorts = [ | |
{ | |
from = "host"; | |
host.port = 2000; | |
guest.port = 22; | |
} | |
]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
debugVm = inputs.nixpkgs.lib.nixosSystem { | |
system = "x86_64-linux"; | |
pkgs = pkgs; | |
modules = prodModules ++ [ ./debug-vm.nix ]; | |
}; | |
scripts.vm-ssh = pkgs.writeShellApplication { | |
name = "vm-ssh"; | |
runtimeInputs = [ | |
pkgs.openssh | |
pkgs.psmisc | |
]; | |
text = '' | |
fuser -k 2000/tcp 2>/dev/null || true | |
${debugVm.config.system.build.vm}/bin/run-nixos-vm & | |
BG_PID=$! | |
ssh [email protected] \ | |
-p 2000 \ | |
-o StrictHostKeyChecking=no \ | |
-o UserKnownHostsFile=/dev/null \ | |
-o ConnectionAttempts=10 | |
kill -s SIGINT $BG_PID | |
''; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment