Source system and user qvm.conf; add memory/cpus options; fix flake path

This commit is contained in:
Joshua Bell 2026-01-26 10:21:23 -06:00
parent e28d1fa14f
commit 8d68e1daf9
4 changed files with 37 additions and 3 deletions

View file

@ -32,9 +32,9 @@ ensure_user_flake() {
# In development: $(dirname "$0")/../flake/default-vm/ # In development: $(dirname "$0")/../flake/default-vm/
local default_flake_dir local default_flake_dir
# Try installed location first # Try installed location first ($QVM_LIB_DIR is $out/lib/qvm)
if [[ -d "$QVM_LIB_DIR/../share/qvm/default-vm" ]]; then if [[ -d "$QVM_LIB_DIR/../../share/qvm/default-vm" ]]; then
default_flake_dir="$QVM_LIB_DIR/../share/qvm/default-vm" default_flake_dir="$QVM_LIB_DIR/../../share/qvm/default-vm"
else else
# Fall back to development location # Fall back to development location
default_flake_dir="$(dirname "$(readlink -f "$0")")/../flake/default-vm" default_flake_dir="$(dirname "$(readlink -f "$0")")/../flake/default-vm"

View file

@ -116,6 +116,15 @@ main() {
# First-run initialization # First-run initialization
ensure_dirs ensure_dirs
# Source config file if it exists (sets QVM_MEMORY, QVM_CPUS, etc.)
# Check system-wide config first, then user config (user overrides system)
if [[ -f "/etc/xdg/qvm/qvm.conf" ]]; then
source "/etc/xdg/qvm/qvm.conf"
fi
if [[ -f "$QVM_CONFIG_FILE" ]]; then
source "$QVM_CONFIG_FILE"
fi
# Check if VM runner exists, build if not # Check if VM runner exists, build if not
if [[ ! -L "$QVM_VM_RUNNER" || ! -f "$(readlink -f "$QVM_VM_RUNNER" 2>/dev/null || echo "")" ]]; then if [[ ! -L "$QVM_VM_RUNNER" || ! -f "$(readlink -f "$QVM_VM_RUNNER" 2>/dev/null || echo "")" ]]; then
log_info "First run detected - building VM..." log_info "First run detected - building VM..."

View file

@ -15,12 +15,36 @@
{ {
nixosModules.default = nixosModules.default =
{ {
config,
lib,
pkgs, pkgs,
... ...
}: }:
let
cfg = config.programs.qvm;
in
{ {
options.programs.qvm = {
memory = lib.mkOption {
type = lib.types.str;
default = "8G";
description = "Amount of memory to allocate to the VM (e.g., '8G', '16G')";
};
cpus = lib.mkOption {
type = lib.types.int;
default = 4;
description = "Number of CPU cores to allocate to the VM";
};
};
config = { config = {
environment.systemPackages = [ self.packages.${pkgs.system}.qvm ]; environment.systemPackages = [ self.packages.${pkgs.system}.qvm ];
environment.etc."xdg/qvm/qvm.conf".text = ''
QVM_MEMORY="${cfg.memory}"
QVM_CPUS="${toString cfg.cpus}"
'';
}; };
}; };
} }

View file

@ -24,6 +24,7 @@ readonly QVM_SERIAL_LOG="$QVM_STATE_DIR/serial.log"
readonly QVM_WORKSPACES_FILE="$QVM_STATE_DIR/workspaces.json" readonly QVM_WORKSPACES_FILE="$QVM_STATE_DIR/workspaces.json"
readonly QVM_USER_FLAKE="$QVM_CONFIG_DIR/flake" readonly QVM_USER_FLAKE="$QVM_CONFIG_DIR/flake"
readonly QVM_VM_RUNNER="$QVM_DATA_DIR/run-vm" readonly QVM_VM_RUNNER="$QVM_DATA_DIR/run-vm"
readonly QVM_CONFIG_FILE="$QVM_CONFIG_DIR/qvm.conf"
# Cache directories for 9p mounts (shared between host and VM) # Cache directories for 9p mounts (shared between host and VM)
readonly QVM_CARGO_HOME="$QVM_CACHE_DIR/cargo-home" readonly QVM_CARGO_HOME="$QVM_CACHE_DIR/cargo-home"