Adding VMs to PATH: Difference between revisions
imported>Kisik21 Described a way to launch NixOS VMs on boot with only Nix |
imported>Olafklingt m add Virtualization Category |
||
(2 intermediate revisions by one other user not shown) | |||
Line 7: | Line 7: | ||
but I don't use it here, because we need another kind of derivation. */ | but I don't use it here, because we need another kind of derivation. */ | ||
nixosVM = configuration: (import <nixpkgs/nixos> { inherit configuration; }).vm; | nixosVM = configuration: (import <nixpkgs/nixos> { inherit configuration; }).vm; | ||
# This is a convenience for having the machine configurations. | |||
vms = { | vms = { | ||
# You can write it inline... | |||
yuki = { config, pkgs, lib, ... }: { | yuki = { config, pkgs, lib, ... }: { | ||
services.httpd.enable = true; | services.httpd.enable = true; | ||
services.httpd.adminAddr = "webmaster@example.com"; | services.httpd.adminAddr = "webmaster@example.com"; | ||
}; | }; | ||
# Or import from another file. | |||
sakura = import VMs/sakura.nix; | sakura = import VMs/sakura.nix; | ||
}; | }; | ||
in { | in { | ||
environment.systemPackages = [ | environment.systemPackages = [ | ||
# Then just add it like this! | |||
(nixosVM vms.yuki) | (nixosVM vms.yuki) | ||
]; | ]; | ||
Line 48: | Line 48: | ||
network_options ? "", | network_options ? "", | ||
args ? "", | args ? "", | ||
diskimagefolder ? "/var/lib/nixos-vms" }: | diskimagefolder ? "/var/lib/nixos-vms", | ||
restartIfChanged ? true }: | |||
let | let | ||
nixos-system = configuration: (import <nixpkgs/nixos> { inherit configuration; }); | nixos-system = configuration: (import <nixpkgs/nixos> { inherit configuration; }); | ||
Line 55: | Line 56: | ||
in { | in { | ||
systemd.services.${hostname} = { | systemd.services.${hostname} = { | ||
inherit after; | inherit after restartIfChanged; | ||
environment = { | environment = { | ||
QEMU_NET_OPTS = network_options; | QEMU_NET_OPTS = network_options; | ||
Line 77: | Line 78: | ||
This will make it launch a virtual machine on boot. | This will make it launch a virtual machine on boot. | ||
[[Category:Virtualization]] |