Cheatsheet: Difference between revisions
imported>Samueldr m → %s/\s\+$//g |
imported>Mic92 headless qemu vms |
||
Line 325: | Line 325: | ||
=== Building a service as a VM (for testing) === | === Building a service as a VM (for testing) === | ||
While | While <code>nixos-rebuild build-vm</code> allows to build a vm out of the current system configuration, there is a more light-weight alternative when only a single service needs to be tested. | ||
Given the following configuration: | Given the following configuration: | ||
Line 340: | Line 340: | ||
a vm can be build using the following command: | a vm can be build using the following command: | ||
<source lang=" | <source lang="console"> | ||
$ nixos-rebuild -I nixpkgs=/path/to/nixpkgs -I nixos-config=./vm.nix build-vm | $ nixos-rebuild -I nixpkgs=/path/to/nixpkgs -I nixos-config=./vm.nix build-vm | ||
</source> | </source> | ||
where | where <code>-I nixpkgs=/path/to/nixpkgs</code> is optionally depending whether the vm should be build from git checkout or a channel. | ||
On non-nixos (linux) systems the following command can be used instead: | On non-nixos (linux) systems the following command can be used instead: | ||
<source lang=" | <source lang="console"> | ||
nix-build '<nixpkgs/nixos>' -A vm -k -I nixos-config=./vm.nix | $ nix-build '<nixpkgs/nixos>' -A vm -k -I nixos-config=./vm.nix | ||
</source> | |||
By default the resulting vm will require X11 to create a virtual display. | |||
By specifying additional arguments via the environment variables <code>QEMU_OPTS</code>and <code>QEMU_KERNEL_PARAMS</code> it is possible to reuse the current running terminal as serial output of the vm: | |||
<source lang="console"> | |||
$ export QEMU_OPTS="-nographic -serial mon:stdio" QEMU_KERNEL_PARAMS=console=ttyS0 | |||
$ /nix/store/lshw31yfbb6izs2s594jd89ma4wf8zw6-nixos-vm/bin/run-nixos-vm | |||
</source> | </source> | ||
Line 362: | Line 370: | ||
</source> | </source> | ||
Add the following | Add the following <code>default.nix</code> to the project: | ||
<source lang="nix"> | <source lang="nix"> |