Skip to content

Commit

Permalink
libvirt: domain: move autostart option
Browse files Browse the repository at this point in the history
  • Loading branch information
j-brn committed Nov 19, 2023
1 parent ce0f3a3 commit 0226102
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 74 deletions.
21 changes: 4 additions & 17 deletions modules/libvirtd/domain.nix
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ let
};
};

domainDefinitionType = types.submodule {
domainType = types.submodule {
options = {
memory = mkOption {
type = memoryOptionsType;
Expand Down Expand Up @@ -540,17 +540,6 @@ let
extra XML appended to the generated domain
'';
};
};
};

domainType = types.submodule {
options = {
definition = mkOption {
type = domainDefinitionType;
description = mdDoc ''
Definition of the domain
'';
};

autostart = mkOption {
type = types.bool;
Expand All @@ -560,7 +549,6 @@ let
'';
};
};

};

mkDomainXml = let
Expand Down Expand Up @@ -828,19 +816,18 @@ let
</domain>
'';

mkDomainXmlPackage = name: definition:
mkDomainXmlPackage = name: domain:
pkgs.runCommand "libvirt-domain-${name}.xml" { } ''
mkdir $out
echo '${mkDomainXml name definition}' > domain.xml
echo '${mkDomainXml name domain}' > domain.xml
${pkgs.libxml2}/bin/xmllint --format domain.xml > $out/domain.xml
cat $out/domain.xml
${pkgs.libvirt}/bin/virt-xml-validate $out/domain.xml
'';

defineDomainsScript = let
xmlPackages = mapAttrsToList mkDomainXmlPackage
(mapAttrs (_: domain: domain.definition) cfg.domains);
xmlPackages = mapAttrsToList mkDomainXmlPackage cfg.domains;
commands = map (xmlPackage: ''
${pkgs.libvirt}/bin/virsh define ${xmlPackage}/domain.xml;
'') xmlPackages;
Expand Down
112 changes: 55 additions & 57 deletions tests/libvirtd/domain.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,76 +18,74 @@ pkgs.nixosTest ({

domains = {
win10 = {
definition = {
memory = {
memory = {
memory = {
value = 1;
unit = "G";
};

disableBallooning = true;
useHugepages = false;
value = 1;
unit = "G";
};

os.enableBootmenu = true;
disableBallooning = true;
useHugepages = false;
};

vcpu = {
count = 2;
placement = "static";
};
os.enableBootmenu = true;

cputune = {
vcpupins = [
{
vcpu = 1;
cpuset = [ 1 ];
}
{
vcpu = 2;
cpuset = [ 2 ];
}
];
};
vcpu = {
count = 2;
placement = "static";
};

cpu = {
topology = {
sockets = 1;
dies = 1;
cores = 2;
threads = 1;
};
};
cputune = {
vcpupins = [
{
vcpu = 1;
cpuset = [ 1 ];
}
{
vcpu = 2;
cpuset = [ 2 ];
}
];
};

input = {
virtioMouse = true;
virtioKeyboard = true;
cpu = {
topology = {
sockets = 1;
dies = 1;
cores = 2;
threads = 1;
};
};

spice = {
spiceAudio = true;
spicemvcChannel = true;
spiceGraphics = true;
};
input = {
virtioMouse = true;
virtioKeyboard = true;
};

pciHostDevices = [{
sourceAddress = {
bus = "0x04";
slot = "0x00";
function = 1;
};
}];
spice = {
spiceAudio = true;
spicemvcChannel = true;
spiceGraphics = true;
};

networkInterfaces = [{ sourceNetwork = "default"; }];
pciHostDevices = [{
sourceAddress = {
bus = "0x04";
slot = "0x00";
function = 1;
};
}];

cdroms = [{
sourceFile = "/opt/someIso.iso";
bootIndex = 1;
}];
networkInterfaces = [{ sourceNetwork = "default"; }];

kvmfr = {
device = "/dev/kvmfr0";
size = "33554432";
};
cdroms = [{
sourceFile = "/opt/someIso.iso";
bootIndex = 1;
}];

kvmfr = {
device = "/dev/kvmfr0";
size = "33554432";
};
};
};
Expand Down

0 comments on commit 0226102

Please sign in to comment.