Skip to content

Instantly share code, notes, and snippets.

@andir
Created September 14, 2018 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andir/88458b13c26a04752854608aacb15c8f to your computer and use it in GitHub Desktop.
Save andir/88458b13c26a04752854608aacb15c8f to your computer and use it in GitHub Desktop.
nixos vm qcow2
{
imports = [
# configure the mountpoint of the root device
({
fileSystems."/".device = "/dev/disk/by-label/nixos";
})
# configure the bootloader
({
boot.loader.grub.extraConfig = ''
serial --unit=0 --speed=115200
terminal_output serial console; terminal_input serial console
'';
boot.kernelParams = [
"console=tty0"
"console=ttyS0,115200n8"
];
boot.loader.grub.device = "/dev/sda";
boot.loader.grub.version = 2;
})
# openssh and user configuration
({
services.openssh.enable = true;
users.users."root".initialPassword = "r00t";
})
];
}
{ pkgs ? import <nixpkgs> {}}:
let
image = (import <nixpkgs/nixos/lib/eval-config.nix> {
modules = [
# expression that exposes the configuration as vm image
({config, lib, pkgs, ...}: {
system.build.qcow2 = import <nixpkgs/nixos/lib/make-disk-image.nix> {
inherit lib config pkgs;
diskSize = 8192;
format = "qcow2-compressed";
configFile = ./configuration.nix;
};
})
./configuration.nix
];
}).config.system.build.qcow2;
in
{
inherit image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment