-
Notifications
You must be signed in to change notification settings - Fork 2
feat: mem and vcpu configurable #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,16 @@ in | |||||||||||||||||||||||||||||||||||||||||
| default = ""; | ||||||||||||||||||||||||||||||||||||||||||
| description = "Agent-specific shell init (runs before launch)"; | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
| mem = lib.mkOption { | ||||||||||||||||||||||||||||||||||||||||||
| type = lib.types.int; | ||||||||||||||||||||||||||||||||||||||||||
| default = 8192; | ||||||||||||||||||||||||||||||||||||||||||
| description = "VM memory in MB. Overridable at runtime via VM_MEM env var."; | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
| vcpu = lib.mkOption { | ||||||||||||||||||||||||||||||||||||||||||
| type = lib.types.int; | ||||||||||||||||||||||||||||||||||||||||||
| default = 4; | ||||||||||||||||||||||||||||||||||||||||||
| description = "VM vCPU count. Overridable at runtime via VM_VCPU env var."; | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+25
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add validation to ensure positive values. The ✅ Proposed validation mem = lib.mkOption {
type = lib.types.int;
default = 8192;
description = "VM memory in MB. Overridable at runtime via VM_MEM env var.";
};
+ # Validate mem is positive
+ assertions = [{
+ assertion = cfg.mem > 0;
+ message = "claude-vm.agent.mem must be greater than 0";
+ }];
+
vcpu = lib.mkOption {
type = lib.types.int;
default = 4;
description = "VM vCPU count. Overridable at runtime via VM_VCPU env var.";
};
+ # Validate vcpu is positive
+ assertions = [{
+ assertion = cfg.vcpu > 0;
+ message = "claude-vm.agent.vcpu must be greater than 0";
+ }];Alternatively, use a more restrictive type: mem = lib.mkOption {
- type = lib.types.int;
+ type = lib.types.ints.positive;
default = 8192;
description = "VM memory in MB. Overridable at runtime via VM_MEM env var.";
};
vcpu = lib.mkOption {
- type = lib.types.int;
+ type = lib.types.ints.positive;
default = 4;
description = "VM vCPU count. Overridable at runtime via VM_VCPU env var.";
};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| config = { | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -31,8 +41,8 @@ in | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| microvm = { | ||||||||||||||||||||||||||||||||||||||||||
| hypervisor = "qemu"; | ||||||||||||||||||||||||||||||||||||||||||
| mem = 4096; | ||||||||||||||||||||||||||||||||||||||||||
| vcpu = 4; | ||||||||||||||||||||||||||||||||||||||||||
| mem = cfg.mem; | ||||||||||||||||||||||||||||||||||||||||||
| vcpu = cfg.vcpu; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| writableStoreOverlay = "/nix/.rw-store"; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add runtime validation for VM_MEM and VM_VCPU.
The script reads
VM_MEMandVM_VCPUfrom the environment without validation. Invalid values (non-numeric, negative, zero) will be passed to QEMU, potentially causing confusing errors.🛡️ Proposed validation
VM_MEM="''${VM_MEM:-${toString defaultMem}}" VM_VCPU="''${VM_VCPU:-${toString defaultVcpu}}" + +# Validate VM_MEM is a positive integer +if ! [[ "$VM_MEM" =~ ^[0-9]+$ ]] || [ "$VM_MEM" -le 0 ]; then + echo "error: VM_MEM must be a positive integer (got: $VM_MEM)" >&2 + exit 1 +fi + +# Validate VM_VCPU is a positive integer +if ! [[ "$VM_VCPU" =~ ^[0-9]+$ ]] || [ "$VM_VCPU" -le 0 ]; then + echo "error: VM_VCPU must be a positive integer (got: $VM_VCPU)" >&2 + exit 1 +fi + RUNTIME="''${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"🤖 Prompt for AI Agents