first VM up and running! still wip
This commit is contained in:
parent
35710f6d3c
commit
0d9e299595
4 changed files with 310 additions and 118 deletions
|
|
@ -1,125 +1,166 @@
|
|||
{ config, pkgs, lib, ... }:
|
||||
with lib;
|
||||
let
|
||||
networkModule = import ./network.nix { inherit config pkgs lib ;};
|
||||
in
|
||||
{
|
||||
options = {
|
||||
cpu =
|
||||
mkOption {
|
||||
type = types.str;
|
||||
default = "host";
|
||||
description = ''
|
||||
The CPU model to emulate.
|
||||
'';
|
||||
};
|
||||
|
||||
smp =
|
||||
mkOption {
|
||||
type = types.ints.positive;
|
||||
default = 1;
|
||||
description = ''
|
||||
Specify the number of cores the guest is permitted to use.
|
||||
The number can be higher than the available cores on the
|
||||
host system.
|
||||
'';
|
||||
};
|
||||
|
||||
memSize =
|
||||
mkOption {
|
||||
type = types.ints.positive;
|
||||
default = 1024;
|
||||
description = ''
|
||||
The memory size in megabytes of the virtual machine.
|
||||
'';
|
||||
};
|
||||
|
||||
diskSize =
|
||||
mkOption {
|
||||
type = types.str;
|
||||
default = "";
|
||||
description = ''
|
||||
The disk size in qemu params.
|
||||
'';
|
||||
};
|
||||
|
||||
osImage =
|
||||
mkOption {
|
||||
type = types.package;
|
||||
description = ''
|
||||
OS image stored in the nix store, either built with vmixLib.images or fetched from the internet.
|
||||
'';
|
||||
};
|
||||
|
||||
persistantOverlayImagePath =
|
||||
mkOption {
|
||||
type = types.nullOr types.path;
|
||||
default = null;
|
||||
description = ''
|
||||
Path where the persistant overlay is stored. If path is non-existant, a qcow2 image backed by the original osImage is created.
|
||||
'';
|
||||
};
|
||||
|
||||
startOnBoot =
|
||||
mkOption {
|
||||
type = types.bool;
|
||||
description = ''
|
||||
Whether to start the VM automatically on system boot.
|
||||
'';
|
||||
default = true;
|
||||
};
|
||||
|
||||
sharedDirectories =
|
||||
lib.mkOption {
|
||||
type = types.attrsOf
|
||||
(types.submodule {
|
||||
options = {
|
||||
source = lib.mkOption {
|
||||
type = types.str;
|
||||
description = "The path of the directory to share, can be a shell variable";
|
||||
};
|
||||
target = lib.mkOption {
|
||||
type = types.str;
|
||||
description = "The mount point of the directory inside the virtual machine";
|
||||
};
|
||||
};
|
||||
});
|
||||
example = {
|
||||
my-share = { source = "/path/to/be/shared"; target = "/mnt/shared"; };
|
||||
cpu.cores = mkOption {
|
||||
type = types.int;
|
||||
default = 2;
|
||||
description = "Number of CPU cores.";
|
||||
};
|
||||
cpu.model = mkOption {
|
||||
type = types.str;
|
||||
default = "host";
|
||||
description = "CPU model.";
|
||||
};
|
||||
kvm = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Enable KVM.";
|
||||
};
|
||||
arch = mkOption {
|
||||
type = types.str;
|
||||
default = "x86_64";
|
||||
description = "Architecture of the VM.";
|
||||
};
|
||||
pc.type = mkOption {
|
||||
type = types.str;
|
||||
default = "q35";
|
||||
description = "PC type.";
|
||||
};
|
||||
bios.efi = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Enable EFI BIOS.";
|
||||
};
|
||||
bios.tpm = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Enable TPM BIOS.";
|
||||
};
|
||||
mem.size = mkOption {
|
||||
type = types.int;
|
||||
default = 1024;
|
||||
description = "Memory size in MB.";
|
||||
};
|
||||
mem.balloon = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Enable memory ballooning.";
|
||||
};
|
||||
disks.os.file = mkOption {
|
||||
type = types.path;
|
||||
description = "Path to the OS disk image.";
|
||||
};
|
||||
disks.os.persist = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Persist OS disk changes.";
|
||||
};
|
||||
disks.iso.file = mkOption {
|
||||
type = types.nullOr types.path;
|
||||
description = "Path to the ISO file.";
|
||||
default = null;
|
||||
};
|
||||
disks.add = mkOption {
|
||||
default = {};
|
||||
type = types.attrsOf (types.submodule {
|
||||
options = {
|
||||
file = mkOption {
|
||||
type = types.path;
|
||||
description = "Path to the additional disk.";
|
||||
};
|
||||
mounts = mkOption {
|
||||
type = types.attrsOf types.str;
|
||||
description = "Mount points for the additional disk.";
|
||||
};
|
||||
opts = mkOption {
|
||||
type = types.str;
|
||||
description = "additional options in QEMU args for this disk";
|
||||
};
|
||||
};
|
||||
default = { };
|
||||
};
|
||||
|
||||
networks = lib.mkOption {
|
||||
type = types.attrsOf
|
||||
(types.submodule networkModule);
|
||||
example = {
|
||||
my-share = { source = "/path/to/be/shared"; target = "/mnt/shared"; };
|
||||
});
|
||||
description = "Additional disks.";
|
||||
};
|
||||
shares = mkOption {
|
||||
default = {};
|
||||
type = types.attrsOf (types.submodule {
|
||||
options = {
|
||||
source = mkOption {
|
||||
type = types.path;
|
||||
description = "Source path for the shared directory.";
|
||||
};
|
||||
target = mkOption {
|
||||
type = types.str;
|
||||
description = "Target path inside the VM for the shared directory.";
|
||||
};
|
||||
};
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
});
|
||||
description = "Shared directories.";
|
||||
};
|
||||
|
||||
functions.mkVMService = name: cfg:
|
||||
let
|
||||
vmCfg = cfg // { inherit name };
|
||||
mkDiskImageFrom
|
||||
diskImage =
|
||||
qemuArgs = ''
|
||||
--name ${vmCfg.name} \
|
||||
--cpu ${vmCfg.cpu} \
|
||||
--smp ${vmCfg.cores} \
|
||||
--
|
||||
'';
|
||||
in
|
||||
{
|
||||
|
||||
};
|
||||
}
|
||||
disks.bus = mkOption {
|
||||
type = types.str;
|
||||
default = "virtio";
|
||||
description = "Bus type for the disks.";
|
||||
};
|
||||
boot.order = mkOption {
|
||||
type = types.listOf types.str;
|
||||
description = "Boot order.";
|
||||
default = [ "os" "iso" ];
|
||||
};
|
||||
boot.menu = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Enable boot menu.";
|
||||
};
|
||||
|
||||
//storage
|
||||
//
|
||||
//networking - DNS, VPNs, Bridges, NATs, isolation, connecting with others,host
|
||||
//run adhoc
|
||||
//run and die
|
||||
//
|
||||
network.user.enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "enable qemu user networking";
|
||||
};
|
||||
|
||||
network.vmix = mkOption {
|
||||
default = {};
|
||||
type = types.attrsOf (types.submodule {
|
||||
options = {
|
||||
lans = mkOption {
|
||||
default = {};
|
||||
type = types.attrsOf (types.submodule {
|
||||
options = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Enable the LAN interface.";
|
||||
};
|
||||
mac = mkOption {
|
||||
type = types.str;
|
||||
description = "MAC address for the LAN interface.";
|
||||
};
|
||||
};
|
||||
});
|
||||
description = "LAN interfaces.";
|
||||
};
|
||||
macvtaps = mkOption {
|
||||
default = {};
|
||||
type = types.attrsOf (types.submodule {
|
||||
options = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Enable the MACVTap interface.";
|
||||
};
|
||||
mac = mkOption {
|
||||
type = types.str;
|
||||
description = "MAC address for the MACVTap interface.";
|
||||
};
|
||||
};
|
||||
});
|
||||
description = "MACVTap interfaces.";
|
||||
};
|
||||
};
|
||||
});
|
||||
description = "Network interfaces.";
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue