uvms: add --mem

Yeah, yeah, I know, it's stupid, adding add_argument() statements
manually, et c. I'll throw the whole Python thing away whenever I might
have the time
This commit is contained in:
Else Someone 2026-03-07 21:16:53 +02:00
parent db4e7809d1
commit cf95fd33b0
2 changed files with 143 additions and 98 deletions

View file

@ -10,6 +10,7 @@ import os
import subprocess import subprocess
import socket import socket
import json import json
import re
from argparse import ArgumentParser from argparse import ArgumentParser
from contextlib import contextmanager, closing, ExitStack from contextlib import contextmanager, closing, ExitStack
@ -20,6 +21,7 @@ parser.add_argument("--prefix", default="$HOME/uvms/$VM")
parser.add_argument("--vm-config", default="@BASE_CONFIG@") # noqa: E501 parser.add_argument("--vm-config", default="@BASE_CONFIG@") # noqa: E501
parser.add_argument("--persist-home", action="store_true") parser.add_argument("--persist-home", action="store_true")
parser.add_argument("--run", action="append") parser.add_argument("--run", action="append")
parser.add_argument("--mem", default=None)
parser.add_argument("app", nargs="*", default=()) parser.add_argument("app", nargs="*", default=())
TOOLS_DIR = "@TOOLS@" # noqa: E501 TOOLS_DIR = "@TOOLS@" # noqa: E501
@ -469,6 +471,21 @@ def connect_ch_vsock(
yield s yield s
BYTES_PATTERN = re.compile(r"^([0-9]+)([MmGgKk]?)$")
BYTES_UNITS = {
"k": 1024,
"m": 1048576,
"g": 1024 * 1048576,
}
def parse_bytes(s):
m = BYTES_PATTERN.match(s)
assert m, s
size, unit = m.groups()
return int(size) * BYTES_UNITS.get(unit.lower(), 1)
@contextmanager @contextmanager
def listen_ch_vsock( def listen_ch_vsock(
vsock_sock_path, vsock_sock_path,
@ -564,6 +581,9 @@ def main(args, args_next, cleanup, ps):
) )
virtiofs_socks.append(("home", sock_path)) virtiofs_socks.append(("home", sock_path))
config["payload"]["cmdline"] += " uvms.persist-home=1" config["payload"]["cmdline"] += " uvms.persist-home=1"
if args.mem is not None:
config["memory"]["size"] = parse_bytes(args.mem)
config["memory"]["hotplug_size"] = parse_bytes(args.mem)
gpud, gpud_path = cleanup.enter_context(ps.start_gpu()) gpud, gpud_path = cleanup.enter_context(ps.start_gpu())

View file

@ -301,121 +301,146 @@ in
}; };
uvms.ch.settings = mkOption { uvms.ch.settings = mkOption {
default = { }; default = { };
type = types.submodule { type = types.submodule (
freeformType = jsonType; let
options = { osConfig = config;
payload = { in
cmdline = mkOption { { config, ... }:
type = types.str; {
default = concatStringsSep " " ( freeformType = jsonType;
config.boot.kernelParams options = {
++ [ payload = {
# "init=${lib.removePrefix "/nix/store" "${config.system.build.toplevel}"}/init" cmdline = mkOption {
"init=${config.system.build.toplevel}/init" type = types.str;
] default = concatStringsSep " " (
); osConfig.boot.kernelParams
defaultText = ''concatStringsSep " " ${config.boot.kernelParams}''; ++ [
# "init=${lib.removePrefix "/nix/store" "${osConfig.system.build.toplevel}"}/init"
"init=${osConfig.system.build.toplevel}/init"
]
);
defaultText = ''concatStringsSep " " ${osConfig.boot.kernelParams}'';
};
kernel = mkOption {
type = types.str;
default = "${kernel}/${kernelTarget}";
};
initramfs = mkOption {
type = types.nullOr types.str;
default = "${initialRamdisk}/${initrdFile}";
};
}; };
kernel = mkOption { vsock = {
type = types.str; cid = mkOption {
default = "${kernel}/${kernelTarget}"; type = types.int;
default = 4;
};
socket = mkOption {
type = types.str;
default = "vsock.sock";
};
}; };
initramfs = mkOption { "api-socket" = mkOption {
type = types.str;
default = "vmm.sock";
};
"serial".mode = mkOption {
type = types.str;
default = "File";
};
"serial".file = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = "${initialRamdisk}/${initrdFile}"; default = "serial";
}; };
}; "console".mode = mkOption {
vsock = {
cid = mkOption {
type = types.int;
default = 4;
};
socket = mkOption {
type = types.str; type = types.str;
default = "vsock.sock"; default = "Pty";
}; };
}; "console".file = mkOption {
"api-socket" = mkOption { type = types.nullOr types.str;
type = types.str; default = null;
default = "vmm.sock"; };
}; # "watchdog" = true;
"serial".mode = mkOption { # "seccomp" = true;
type = types.str; disks = mkOption {
default = "File"; default = [ ];
}; type = types.listOf (
"serial".file = mkOption { types.submodule {
type = types.nullOr types.str; freeformType = jsonType;
default = "serial"; options = {
}; path = mkOption {
"console".mode = mkOption { type = types.oneOf [
type = types.str; types.path
default = "Pty"; types.str
}; ];
"console".file = mkOption { };
type = types.nullOr types.str; readonly = mkOption {
default = null; type = types.bool;
}; default = true;
# "watchdog" = true; };
# "seccomp" = true; id = mkOption { type = types.str; };
disks = mkOption { };
default = [ ]; }
type = types.listOf ( );
types.submodule { };
memory = mkOption {
default = { };
type = types.submodule {
freeformType = jsonType; freeformType = jsonType;
options = { options = {
path = mkOption { size = mkOption {
type = types.oneOf [ type = types.int;
types.path default = 2 * 1024 * 1048576;
types.str
];
}; };
readonly = mkOption { shared = mkOption {
type = types.bool; type = types.bool;
default = true; default = true;
}; };
id = mkOption { type = types.str; }; mergeable = mkOption {
type = types.bool;
default = true;
};
hotplug_method = mkOption {
default = "VirtioMem";
type = types.enum [
"Acpi"
"VirtioMem"
];
};
hotplugged_size = mkOption {
type = types.int;
default = 512 * 1048576;
};
hotplug_size = mkOption {
type = types.int;
default = config.memory.size;
};
# hugepages = mkOption {
# type = types.bool;
# default = true;
# };
}; };
} };
); };
}; cpus = mkOption {
memory = mkOption { default = { };
default = { }; type = types.submodule {
type = types.submodule { freeformType = jsonType;
freeformType = jsonType; options = {
options = { boot_vcpus = mkOption {
size = mkOption { type = types.int;
type = types.int; default = 4;
default = 3 * 1024 * 1048576; };
}; max_vcpus = mkOption {
shared = mkOption { type = types.int;
type = types.bool; default = 4;
default = true; };
};
mergeable = mkOption {
type = types.bool;
default = true;
}; };
}; };
}; };
}; };
cpus = mkOption { }
default = { }; );
type = types.submodule {
freeformType = jsonType;
options = {
boot_vcpus = mkOption {
type = types.int;
default = 4;
};
max_vcpus = mkOption {
type = types.int;
default = 4;
};
};
};
};
};
};
}; };
}; };
} }