diff --git a/README.md b/README.md index 652f3ff..16a8916 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,5 @@ nix-build vm.nix -A system.build.customVM ssh debian@localhost -p 2222 # Inside VM after SSH watch -n 1 "cat /var/log/cloud-init-output.log | tail" -cat /var/log/cloud-init.log -ls -la /home/debian/ ``` +4. After a while, the Jupyter URL will spawn diff --git a/vm.nix b/vm.nix index 8c9e6c4..030643d 100644 --- a/vm.nix +++ b/vm.nix @@ -38,7 +38,7 @@ let users: - name: debian sudo: ALL=(ALL) NOPASSWD:ALL - groups: sudo, users, adm, video, render + groups: sudo, users, adm shell: /bin/bash lock_passwd: false passwd: nixos @@ -57,41 +57,34 @@ chpasswd: package_update: true package_upgrade: true -# Install packages - ADDED GPU DRIVERS +# Install packages packages: - git - - firefox-esr - - sway - - sudo - curl - wget - # GPU/Display drivers - - mesa-vulkan-drivers - - libgl1-mesa-dri - - xwayland - - seatd - # Utilities - - dbus-x11 - - xdg-utils - - policykit-1 -# Write setup script -write_files: - - path: /home/debian/first-boot-setup.sh - owner: debian:debian - permissions: '0755' - content: | - #!/bin/bash +# Run commands - FIXED: Moved all setup to runcmd instead of write_files +runcmd: + # Configure sudo + - [sed, -i, '/^%sudo/s/ALL$/NOPASSWD:ALL/', /etc/sudoers] + + # Create log directory + - [mkdir, -p, /var/log] + + # Update and install packages + - [apt-get, update] + - [apt-get, install, -y, git, curl, wget] + + # Set up user environment + - [chown, -R, debian:debian, /home/debian] + - [chmod, 700, /home/debian] + + # Execute setup as debian user - FIXED: All commands in one script + - | + su - debian -c ' set -e echo "Starting first-boot setup as debian user..." - # Enable seatd service for non-systemd login - sudo systemctl enable seatd || true - sudo systemctl start seatd || true - - # Add user to necessary groups for Wayland - sudo usermod -a -G video,render,seat,input debian - # Clone repository cd /home/debian echo "Cloning GRCon23Tutorial repository..." @@ -103,85 +96,41 @@ write_files: chmod +x install.sh ./install.sh - cat > ~/start-sway.sh << 'LAUNCHEREOF' - #!/bin/bash - # Start a bare X server with a virtual display - Xorg :10 -ac -screen 1024x768 & - XPID=$! - # Set the DISPLAY environment variable for the new X server - export DISPLAY=:10 - # Wait for X to be ready, then start Sway using XWayland - sleep 2 - dbus-run-session sway --unsupported-gpu - # Cleanup: when Sway exits, kill the X server - kill $XPID - LAUNCHEREOF - - chmod +x ~/start-sway.sh - echo "Created launcher script: ~/start-sway.sh" + # Source conda and start Jupyter Lab + echo "Setting up conda environment and starting Jupyter Lab..." + source "/home/debian/conda/etc/profile.d/conda.sh" + conda activate GRCon23 + jupyter-lab --ip=0.0.0.0 --port=8888 --no-browser & + JUPYTER_PID=$! + echo $JUPYTER_PID > /tmp/jupyter.pid + echo "Jupyter Lab started with PID: $JUPYTER_PID" echo "First-boot setup completed!" - echo "Installed packages:" - dpkg -l git firefox-esr sway mesa-vulkan-drivers | grep ^ii + echo "Jupyter Lab running on port 8888" + ' - # Create marker file - sudo touch /etc/vm-initialized - echo "User setup completed at $(date)" | sudo tee -a /var/log/vm-init.log - -# Run commands -runcmd: - # Configure sudo - - [sed, -i, '/^%sudo/s/ALL$/NOPASSWD:ALL/', /etc/sudoers] - - # Create log directory - - [mkdir, -p, /var/log] - - # Update and install packages - - [apt-get, update] - - [apt-get, install, -y, git, firefox-esr, sway, sudo, mesa-vulkan-drivers, libgl1-mesa-dri, xwayland, seatd, dbus-x11] - - # Set up user environment - - [chown, -R, debian:debian, /home/debian] - - [chmod, 700, /home/debian] - - # Enable services - - [systemctl, enable, seatd] - - [systemctl, start, seatd] - - # Run user setup - - [sudo, -u, debian, /bin/bash, /home/debian/first-boot-setup.sh] - - # Final setup + # Create marker file + - [touch, /etc/vm-initialized] - [echo, "VM setup completed at $(date)", ">>", /var/log/vm-init.log] - - [echo, "User groups:", ">>", /var/log/vm-init.log] - - [groups, debian, ">>", /var/log/vm-init.log] + - [echo, "Jupyter Lab should be running on port 8888", ">>", /var/log/vm-init.log] # Final message final_message: | VM initialization complete! - For Sway/Wayland to work: - 1. The VM needs GPU acceleration - 2. User 'debian' added to video, render, seat groups - 3. seatd service enabled for Wayland sessions + Setup completed: + 1. Git cloned GRCon23Tutorial repository + 2. Ran ./install.sh + 3. Started Jupyter Lab on port 8888 - Login with: - Username: debian + Access: + SSH: ssh debian@localhost -p 2222 Password: nixos + Jupyter Lab: http://localhost:8888 (forwarded from VM port 8888) - To start Sway manually: - sway --unsupported-gpu - - Or SSH and run: dbus-run-session sway - - Important: Sway is installed but requires a workaround for the virtual environment. - - To start Sway: - 1. SSH into the VM: ssh debian@localhost -p 2222 - 2. Run the launcher script: ~/start-sway.sh - - This script starts an X server and runs Sway within it using XWayland. - The display will be accessible via the QEMU GTK window. + Check status in VM: + sudo journalctl -u cloud-init + cat /var/log/vm-init.log EOF # Create cloud-init ISO @@ -190,10 +139,15 @@ EOF "${vmDataDir}/user-data" echo "VM files created in ${vmDataDir}" - echo "First boot will set up GPU acceleration for Sway" + echo "First boot will:" + echo "1. Clone GRCon23Tutorial repository" + echo "2. Run ./install.sh" + echo "3. Start Jupyter Lab on port 8888" + echo "" + echo "Access Jupyter at: http://localhost:8888" ''; - # 4. LAUNCH SCRIPT WITH GPU SUPPORT + # 4. LAUNCH SCRIPT WITH PORT FORWARDING runScript = pkgs.writeShellScriptBin "run-debian-vm" '' set -e @@ -207,42 +161,33 @@ EOF sleep 2 fi - echo "Starting Debian VM with GPU acceleration..." + echo "Starting Debian VM..." echo "" - echo "GPU/Display configuration:" - echo "- Using virtio-gpu-pci with OpenGL" - echo "- User added to video, render groups" - echo "- Mesa Vulkan drivers installed" - echo "- seatd service enabled for Wayland" + echo "First boot will:" + echo "1. Clone GRCon23Tutorial repository" + echo "2. Run ./install.sh" + echo "3. Start Jupyter Lab on port 8888" echo "" - echo "After boot, to start Sway:" + echo "Access after boot:" echo " SSH: ssh debian@localhost -p 2222" - echo " Password: nixos" - echo " Then run: dbus-run-session sway" - echo " Or: sway --unsupported-gpu" + echo " Jupyter: http://localhost:8888" + echo " Password for 'debian' user: nixos" echo "" - echo "Press Ctrl+Alt+G to release mouse" + echo "Press Ctrl+Alt+G to release mouse from VM window" - # Launch QEMU with GPU acceleration + # Launch QEMU with port 8888 forwarded ${pkgs.qemu_kvm}/bin/qemu-kvm \ -name "Debian-GRCon-VM" \ - -machine q35,accel=kvm \ - -cpu host,-hypervisor \ - -smp 4 \ - -m 4096 \ + -machine accel=kvm \ + -cpu host \ + -smp 2 \ + -m 2048 \ -drive file="${vmDataDir}/debian-persistent.qcow2",format=qcow2,if=virtio \ -drive file="${vmDataDir}/cloud-init.iso",format=raw,if=virtio \ - -netdev user,id=n1,hostfwd=tcp::2222-:22 \ + -netdev user,id=n1,hostfwd=tcp::2222-:22,hostfwd=tcp::8888-:8888 \ -device virtio-net-pci,netdev=n1 \ - # GPU CONFIGURATION: - -device virtio-vga-gl \ - -display gtk,gl=on \ - -device virtio-keyboard-pci \ - -device virtio-mouse-pci \ - -device usb-tablet \ - -audiodev pa,id=audio0,server=/run/user/1000/pulse/native \ - -device AC97,audiodev=audio0 \ - -vga none \ + -display gtk \ + -vga virtio \ "$@" '';