let sources = import ./npins; system = builtins.currentSystem; pkgs = import sources.nixpkgs { inherit system; config.allowUnfree = true; }; claudeCode = pkgs.callPackage "${sources.claude-code-nix}/package.nix" { }; nixosCfg = import "${sources.nixpkgs}/nixos/lib/eval-config.nix" { inherit system; specialArgs = { inherit sources; }; modules = [ { nixpkgs.pkgs = pkgs; } ( { modulesPath, ... }: { imports = [ "${modulesPath}/virtualisation/qemu-vm.nix" ]; virtualisation = { graphics = false; memorySize = 4096; cores = 4; sharedDirectories = { workspace = { source = ''"$WORKSPACE_DIR"''; target = "/workspace"; securityModel = "none"; }; config = { source = ''"$CLAUDE_VM_CONFIG_DIR"''; target = "/mnt/claude-vm-config"; securityModel = "none"; }; }; }; boot = { kernelParams = [ "console=ttyS0" ]; loader.grub.enable = false; initrd.kernelModules = [ "9p" "9pnet_virtio" ]; }; users.users.claude = { isNormalUser = true; home = "/home/claude"; extraGroups = [ "wheel" ]; }; services.getty.autologinUser = "claude"; services.udisks2.enable = false; programs.command-not-found.enable = false; # packages environment.systemPackages = [ claudeCode pkgs.git pkgs.curl pkgs.vim ]; # login shell launches claude programs.bash.interactiveShellInit = '' # Only run for the auto-login claude user [ "$(whoami)" = "claude" ] || return args=() if [ -f /mnt/claude-vm-config/claude-args ]; then while IFS= read -r line; do [ -n "$line" ] && args+=("$line") done < /mnt/claude-vm-config/claude-args fi cd /workspace 2>/dev/null || true exec claude "''${args[@]}" ''; # misc networking.hostName = "claude-vm"; system.stateVersion = "25.05"; } ) ]; }; vmBuild = nixosCfg.config.system.build.vm; in { claude-vm = pkgs.writeShellScriptBin "claude-vm" '' CONFIG_DIR=$(mktemp -d) trap "rm -rf '$CONFIG_DIR'" EXIT # Write all CLI args to a file, one per line if [ $# -gt 0 ]; then printf '%s\n' "$@" > "$CONFIG_DIR/claude-args" else touch "$CONFIG_DIR/claude-args" fi export CLAUDE_VM_CONFIG_DIR="$CONFIG_DIR" export WORKSPACE_DIR="$(pwd)" ${vmBuild}/bin/run-claude-vm-vm ''; }