Replace Bash qvm scripts with Go CLI implementation
This commit is contained in:
parent
ffb456707f
commit
2a6a333721
27 changed files with 2551 additions and 1702 deletions
1059
flake/default-vm/flake.lock
generated
Normal file
1059
flake/default-vm/flake.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -8,11 +8,6 @@
|
|||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
nixos-generators = {
|
||||
url = "github:nix-community/nixos-generators";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
opencode.url = "github:anomalyco/opencode";
|
||||
common.url = "git+https://git.joshuabell.xyz/ringofstorms/dotfiles?dir=flakes/common";
|
||||
ros_neovim.url = "git+https://git.joshuabell.xyz/ringofstorms/nvim";
|
||||
|
|
@ -22,7 +17,6 @@
|
|||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
nixos-generators,
|
||||
...
|
||||
}@inputs:
|
||||
let
|
||||
|
|
@ -52,6 +46,33 @@
|
|||
allowUnfreePredicate = (_: true);
|
||||
};
|
||||
|
||||
# Root filesystem configuration for disk image
|
||||
# Use /dev/vda1 directly instead of by-label to avoid initrd label detection issues
|
||||
fileSystems."/" = {
|
||||
device = "/dev/vda1";
|
||||
autoResize = true;
|
||||
fsType = "ext4";
|
||||
};
|
||||
|
||||
# Boot loader configuration for disk image
|
||||
boot.loader.grub.device = lib.mkDefault "/dev/vda";
|
||||
|
||||
# Explicitly load virtio block device module in initrd
|
||||
boot.initrd.availableKernelModules = [ "virtio_blk" "virtio_pci" "virtio" ];
|
||||
|
||||
# Serial console for headless operation with QEMU -nographic
|
||||
boot.kernelParams = [ "console=ttyS0,115200n8" ];
|
||||
|
||||
# GRUB serial console configuration
|
||||
boot.loader.grub.extraConfig = ''
|
||||
serial --unit=0 --speed=115200
|
||||
terminal_input serial
|
||||
terminal_output serial
|
||||
'';
|
||||
|
||||
# Getty on serial console for login prompt
|
||||
systemd.services."serial-getty@ttyS0".enable = true;
|
||||
|
||||
# Distinctive hostname for easy identification
|
||||
networking.hostName = "qvm-dev";
|
||||
|
||||
|
|
@ -184,9 +205,60 @@
|
|||
SCCACHE_DIR = "/cache/sccache";
|
||||
};
|
||||
|
||||
# Ensure workspace directory exists
|
||||
# Ensure workspace and cache directories exist
|
||||
systemd.tmpfiles.rules = [
|
||||
"d /workspace 0755 root root -"
|
||||
"d /cache 0755 root root -"
|
||||
"d /cache/cargo 0755 root root -"
|
||||
"d /cache/target 0755 root root -"
|
||||
"d /cache/pnpm 0755 root root -"
|
||||
"d /cache/sccache 0755 root root -"
|
||||
];
|
||||
|
||||
# Systemd mount units for cache directories
|
||||
# The NixOS VM runner doesn't include custom fileSystems entries in the generated fstab,
|
||||
# so we use systemd mount units to automount the 9p virtfs shares at boot.
|
||||
systemd.mounts = [
|
||||
{
|
||||
what = "cargo_home";
|
||||
where = "/cache/cargo";
|
||||
type = "9p";
|
||||
options = "trans=virtio,version=9p2000.L,msize=104857600,nofail";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "systemd-modules-load.service" ];
|
||||
}
|
||||
{
|
||||
what = "cargo_target";
|
||||
where = "/cache/target";
|
||||
type = "9p";
|
||||
options = "trans=virtio,version=9p2000.L,msize=104857600,nofail";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "systemd-modules-load.service" ];
|
||||
}
|
||||
{
|
||||
what = "pnpm_store";
|
||||
where = "/cache/pnpm";
|
||||
type = "9p";
|
||||
options = "trans=virtio,version=9p2000.L,msize=104857600,nofail";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "systemd-modules-load.service" ];
|
||||
}
|
||||
{
|
||||
what = "sccache";
|
||||
where = "/cache/sccache";
|
||||
type = "9p";
|
||||
options = "trans=virtio,version=9p2000.L,msize=104857600,nofail";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "systemd-modules-load.service" ];
|
||||
}
|
||||
{
|
||||
what = "opencode_config";
|
||||
where = "/root/.config/opencode";
|
||||
type = "9p";
|
||||
options = "trans=virtio,version=9p2000.L,msize=104857600,nofail";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "systemd-modules-load.service" ];
|
||||
}
|
||||
];
|
||||
|
||||
# Essential packages for development
|
||||
|
|
@ -224,6 +296,16 @@
|
|||
# GB disk size
|
||||
virtualisation.diskSize = 40 * 1024;
|
||||
|
||||
# NOTE: Using 9p virtfs for filesystem sharing
|
||||
# The NixOS VM runner doesn't support virtio-fs out of the box.
|
||||
# We use 9p (-virtfs) which is the standard method for QEMU VMs.
|
||||
#
|
||||
# See: https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/virtualisation/qemu-vm.nix#L530
|
||||
# The sharedDirectories option hardcodes: -virtfs local,path=...,security_model=...
|
||||
#
|
||||
# 9p mounts are configured via QEMU_OPTS environment variable:
|
||||
# -virtfs local,path=$HOST_PATH,mount_tag=$TAG,security_model=mapped-xattr,msize=104857600
|
||||
|
||||
system.stateVersion = stateVersion;
|
||||
};
|
||||
|
||||
|
|
@ -243,8 +325,28 @@
|
|||
|
||||
# Runnable VM script (./result/bin/run-qvm-dev-vm)
|
||||
packages.${system} = {
|
||||
# QCOW2 disk image for base VM
|
||||
# Using make-disk-image.nix with sufficient memSize to avoid OOM during build
|
||||
default = import "${nixpkgs}/nixos/lib/make-disk-image.nix" {
|
||||
inherit pkgs;
|
||||
lib = nixpkgs.lib;
|
||||
config = baseVm.config;
|
||||
|
||||
# Disk image settings
|
||||
format = "qcow2";
|
||||
diskSize = "auto";
|
||||
additionalSpace = "2G"; # Extra space beyond closure size (default 512M)
|
||||
partitionTableType = "legacy"; # Use simple MBR instead of hybrid
|
||||
label = "nixos"; # Explicit label matching fileSystems."/" device
|
||||
|
||||
# CRITICAL: Increase build VM memory to 16GB for large closures
|
||||
# The closure includes NixOS + home-manager + opencode + dev tools (~2GB+)
|
||||
# Default 512MB and even 2GB was insufficient, causing OOM during cptofs
|
||||
memSize = 16384;
|
||||
};
|
||||
|
||||
# Keep the runner script as an alternative for debugging
|
||||
vm = baseVm.config.system.build.vm;
|
||||
default = baseVm.config.system.build.vm;
|
||||
};
|
||||
|
||||
apps.${system}.default = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue