Skip to content

Instantly share code, notes, and snippets.

@Mic92
Created November 5, 2020 18:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mic92/c62a47b0cf57c711b728196b09491b81 to your computer and use it in GitHub Desktop.
Save Mic92/c62a47b0cf57c711b728196b09491b81 to your computer and use it in GitHub Desktop.
# $ nix-build minimal-vm.nix
# $ cp ./result/nixos.qcow2 . && chmod +w nixos.qcow2
# $ qemu-system-x86_64 -s -S \
# -kernel arch/x86/boot/bzImage \
# -hda nixos.qcow2 \
# -append "root=/dev/sda console=ttyS0 nokalsr" \
# -nographic -enable-kvm
{ pkgs ? import <nixpkgs> {} }:
import (pkgs.path + "/nixos/lib/make-disk-image.nix") {
inherit pkgs;
inherit (pkgs) lib;
config = (import (pkgs.path + "/nixos/lib/eval-config.nix") {
inherit (pkgs) system;
modules = [{
imports = [
(pkgs.path + "/nixos/modules/profiles/qemu-guest.nix")
];
boot.loader.grub.enable = false;
boot.initrd.enable = false;
boot.isContainer = true;
boot.loader.initScript.enable = true;
# login with empty password
users.extraUsers.root.initialHashedPassword = "";
services.mingetty.helpLine = ''
Log in as "root" with an empty password.
If you are connect via serial console:
Type Ctrl-a c to switch to the qemu console
and `quit` to stop the VM.
'';
documentation.doc.enable = false;
}];
}).config;
partitionTableType = "none";
diskSize = 8192;
format = "qcow2";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment