mirror of
https://github.com/CHN-beta/nixos.git
synced 2026-01-12 04:39:23 +08:00
modules.services.nixvirt: allow cpu isolation
This commit is contained in:
@@ -37,13 +37,13 @@ inputs:
|
||||
alikia =
|
||||
{
|
||||
memory.sizeMB = 1024;
|
||||
cpus = 1;
|
||||
cpu.count = 1;
|
||||
network = { address = 2; portForward.tcp = [{ host = 5689; guest = 22; }]; };
|
||||
};
|
||||
pen =
|
||||
{
|
||||
memory.sizeMB = 512;
|
||||
cpus = 1;
|
||||
cpu.count = 1;
|
||||
network =
|
||||
{
|
||||
address = 3;
|
||||
@@ -65,7 +65,7 @@ inputs:
|
||||
{
|
||||
owner = "chn";
|
||||
memory.sizeMB = 512;
|
||||
cpus = 1;
|
||||
cpu.count = 1;
|
||||
network =
|
||||
{
|
||||
address = 4;
|
||||
@@ -76,7 +76,7 @@ inputs:
|
||||
reonokiy =
|
||||
{
|
||||
memory.sizeMB = 4 * 1024;
|
||||
cpus = 4;
|
||||
cpu.count = 4;
|
||||
network = { address = 5; portForward.tcp = [{ host = 5694; guest = 22; }]; };
|
||||
};
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ inputs:
|
||||
chn =
|
||||
{
|
||||
memory.sizeMB = 2048;
|
||||
cpus = 4;
|
||||
cpu.count = 4;
|
||||
network =
|
||||
{
|
||||
address = 2;
|
||||
@@ -41,7 +41,7 @@ inputs:
|
||||
{
|
||||
owner = "chn";
|
||||
memory.sizeMB = 2048;
|
||||
cpus = 4;
|
||||
cpu.count = 4;
|
||||
network = { address = 3; portForward.tcp = [{ host = 5694; guest = 22; }]; };
|
||||
};
|
||||
};
|
||||
|
||||
@@ -28,7 +28,12 @@ inputs:
|
||||
sizeMB = mkOption { type = types.ints.unsigned; };
|
||||
dedicate = mkOption { type = types.bool; default = false; };
|
||||
};
|
||||
cpus = mkOption { type = types.ints.unsigned; };
|
||||
cpu =
|
||||
{
|
||||
count = mkOption { type = types.ints.unsigned; };
|
||||
hyprthread = mkOption { type = types.bool; default = false; };
|
||||
cpuset = mkOption { type = types.nullOr types.nonEmptyStr; default = null; };
|
||||
};
|
||||
network =
|
||||
{
|
||||
mac = mkOption { type = types.nonEmptyStr; default = defaultMac; };
|
||||
@@ -143,7 +148,7 @@ inputs:
|
||||
inherit (vm) name;
|
||||
inherit (vm.value) uuid;
|
||||
type = "kvm";
|
||||
vcpu = { placement = "static"; count = vm.value.cpus; };
|
||||
vcpu = { placement = "static"; count = vm.value.cpu.count; inherit (vm.value.cpu) cpuset; };
|
||||
memory =
|
||||
{
|
||||
count = vm.value.memory.sizeMB;
|
||||
@@ -170,7 +175,13 @@ inputs:
|
||||
cpu =
|
||||
{
|
||||
mode = "host-passthrough";
|
||||
topology = { sockets = 1; dies = 1; cores = vm.value.cpus; threads = 1; };
|
||||
topology =
|
||||
{
|
||||
sockets = 1;
|
||||
dies = 1;
|
||||
cores = if vm.value.cpu.hyprthread then vm.value.cpu.count / 2 else vm.value.cpu.count;
|
||||
threads = if vm.value.cpu.hyprthread then 2 else 1;
|
||||
};
|
||||
};
|
||||
clock =
|
||||
{
|
||||
@@ -306,5 +317,9 @@ inputs:
|
||||
};
|
||||
wantedBy= [ "multi-user.target" ];
|
||||
};
|
||||
boot.kernelParams =
|
||||
let cpusets = builtins.filter builtins.isString
|
||||
(builtins.map (vm: vm.cpu.cpuset) (builtins.attrValues nixvirt.instance));
|
||||
in inputs.lib.mkIf (cpusets != []) [ "isolcpus=${builtins.concatStringsSep "," cpusets}" ];
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user