Skip to content

Instantly share code, notes, and snippets.

@aabccd021
Created June 18, 2025 04:46
Show Gist options
  • Save aabccd021/e0c381f0675f07a63e7a7dd68fb922fc to your computer and use it in GitHub Desktop.
Save aabccd021/e0c381f0675f07a63e7a7dd68fb922fc to your computer and use it in GitHub Desktop.
NixOS debug vm
{ 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;
}
];
}
{
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