nixos/vms: Add disk support
This commit is contained in:
parent
1a61c9e1b2
commit
a907ae428f
@ -4,7 +4,7 @@
|
|||||||
nixpkgs = "mine";
|
nixpkgs = "mine";
|
||||||
home-manager = "unstable";
|
home-manager = "unstable";
|
||||||
|
|
||||||
configuration = { lib, pkgs, modulesPath, config, ... }:
|
configuration = { lib, pkgs, modulesPath, config, systems, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) mkIf;
|
inherit (lib) mkIf;
|
||||||
in
|
in
|
||||||
@ -40,7 +40,20 @@
|
|||||||
vms = {
|
vms = {
|
||||||
instances.test = {
|
instances.test = {
|
||||||
networks.virtual = {};
|
networks.virtual = {};
|
||||||
vga = "none";
|
drives = {
|
||||||
|
disk = {
|
||||||
|
backend = {
|
||||||
|
driver = "file";
|
||||||
|
filename = "${systems.installer.configuration.config.my.buildAs.iso}/iso/nixos.iso";
|
||||||
|
read-only = "on";
|
||||||
|
};
|
||||||
|
format.driver = "raw";
|
||||||
|
frontend = "ide-cd";
|
||||||
|
frontendOpts = {
|
||||||
|
bootindex = 0;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
nixos.systems.installer = {
|
nixos.systems.installer = {
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
nixpkgs = "unstable";
|
nixpkgs = "mine";
|
||||||
docCustom = false;
|
docCustom = false;
|
||||||
|
|
||||||
configuration =
|
configuration =
|
||||||
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
config = {
|
config = {
|
||||||
my = {
|
my = {
|
||||||
# Whatever installer mechanism is chosen will provied an appropriate `/`
|
# Whatever installer mechanism is chosen will provide an appropriate `/`
|
||||||
tmproot.enable = false;
|
tmproot.enable = false;
|
||||||
firewall.nat.enable = false;
|
firewall.nat.enable = false;
|
||||||
deploy.enable = false;
|
deploy.enable = false;
|
||||||
|
@ -22,6 +22,18 @@ let
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
driveOpts = with lib.types; {
|
||||||
|
options = {
|
||||||
|
backend = mkOpt' qemuOpts { } "Backend blockdev options.";
|
||||||
|
|
||||||
|
format = mkOpt' qemuOpts { } "Format blockdev options.";
|
||||||
|
formatBackendProp = mkOpt' str "file" "Property that references the backend blockdev.";
|
||||||
|
|
||||||
|
frontend = mkOpt' str "virtio-blk" "Frontend device driver.";
|
||||||
|
frontendOpts = mkOpt' qemuOpts { } "Frontend device options.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
vmOpts = with lib.types; { name, ... }: {
|
vmOpts = with lib.types; { name, ... }: {
|
||||||
options = {
|
options = {
|
||||||
qemuBin = mkOpt' path "${pkgs.qemu_kvm}/bin/qemu-kvm" "Path to QEMU executable.";
|
qemuBin = mkOpt' path "${pkgs.qemu_kvm}/bin/qemu-kvm" "Path to QEMU executable.";
|
||||||
@ -40,6 +52,7 @@ let
|
|||||||
vga = mkOpt' str "qxl" "VGA card type.";
|
vga = mkOpt' str "qxl" "VGA card type.";
|
||||||
spice.enable = mkBoolOpt' true "Whether to enable SPICE.";
|
spice.enable = mkBoolOpt' true "Whether to enable SPICE.";
|
||||||
networks = mkOpt' (attrsOf (submodule netOpts)) { } "Networks to attach VM to.";
|
networks = mkOpt' (attrsOf (submodule netOpts)) { } "Networks to attach VM to.";
|
||||||
|
drives = mkOpt' (attrsOf (submodule driveOpts)) { } "Drives to attach to VM.";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -61,15 +74,20 @@ let
|
|||||||
"device isa-serial,chardev=tty"
|
"device isa-serial,chardev=tty"
|
||||||
] ++
|
] ++
|
||||||
(optional i.enableKVM "enable-kvm") ++
|
(optional i.enableKVM "enable-kvm") ++
|
||||||
|
(optionals i.enableUEFI [
|
||||||
|
"drive if=pflash,format=raw,unit=0,readonly=on,file=${cfg.ovmfPackage.fd}/FV/OVMF_CODE.fd"
|
||||||
|
"drive if=pflash,format=raw,unit=1,file=/var/lib/vms/${n}/ovmf_vars.bin"
|
||||||
|
]) ++
|
||||||
(optional i.spice.enable "spice unix=on,addr=/run/vms/${n}/spice.sock,disable-ticketing=on") ++
|
(optional i.spice.enable "spice unix=on,addr=/run/vms/${n}/spice.sock,disable-ticketing=on") ++
|
||||||
(flatten (mapAttrsToList (nn: c: [
|
(flatten (mapAttrsToList (nn: c: [
|
||||||
"netdev bridge,id=${nn},br=${c.bridge}"
|
"netdev bridge,id=${nn},br=${c.bridge}"
|
||||||
("device ${c.model},netdev=${nn}" + (extraQEMUOpts c.extraOptions))
|
("device ${c.model},netdev=${nn}" + (extraQEMUOpts c.extraOptions))
|
||||||
]) i.networks)) ++
|
]) i.networks)) ++
|
||||||
(optionals i.enableUEFI [
|
(flatten (mapAttrsToList (dn: c: [
|
||||||
"drive if=pflash,format=raw,unit=0,readonly=on,file=${cfg.ovmfPackage.fd}/FV/OVMF_CODE.fd"
|
"blockdev node-name=${dn}-backend,${c.backend}"
|
||||||
"drive if=pflash,format=raw,unit=1,file=/var/lib/vms/${n}/ovmf_vars.bin"
|
"blockdev node-name=${dn}-format,${c.formatBackendProp}=${dn}-backend,${c.format}"
|
||||||
]);
|
("device ${c.frontend},id=${dn},drive=${dn}-format" + (extraQEMUOpts c.frontendOpts))
|
||||||
|
]) i.drives));
|
||||||
args = map (v: "-${v}") flags;
|
args = map (v: "-${v}") flags;
|
||||||
in
|
in
|
||||||
concatStringsSep " " ([ i.qemuBin ] ++ args);
|
concatStringsSep " " ([ i.qemuBin ] ++ args);
|
||||||
|
Loading…
Reference in New Issue
Block a user