Working version: Jupyter exposed on host

unattended install achieved !
This commit is contained in:
2026-02-08 00:40:08 +02:00
parent c330054da6
commit e5ae18155a
2 changed files with 69 additions and 125 deletions

View File

@@ -20,6 +20,5 @@ nix-build vm.nix -A system.build.customVM
ssh debian@localhost -p 2222 ssh debian@localhost -p 2222
# Inside VM after SSH # Inside VM after SSH
watch -n 1 "cat /var/log/cloud-init-output.log | tail" 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

191
vm.nix
View File

@@ -38,7 +38,7 @@ let
users: users:
- name: debian - name: debian
sudo: ALL=(ALL) NOPASSWD:ALL sudo: ALL=(ALL) NOPASSWD:ALL
groups: sudo, users, adm, video, render groups: sudo, users, adm
shell: /bin/bash shell: /bin/bash
lock_passwd: false lock_passwd: false
passwd: nixos passwd: nixos
@@ -57,41 +57,34 @@ chpasswd:
package_update: true package_update: true
package_upgrade: true package_upgrade: true
# Install packages - ADDED GPU DRIVERS # Install packages
packages: packages:
- git - git
- firefox-esr
- sway
- sudo
- curl - curl
- wget - wget
# GPU/Display drivers
- mesa-vulkan-drivers
- libgl1-mesa-dri
- xwayland
- seatd
# Utilities
- dbus-x11
- xdg-utils
- policykit-1
# Write setup script # Run commands - FIXED: Moved all setup to runcmd instead of write_files
write_files: runcmd:
- path: /home/debian/first-boot-setup.sh # Configure sudo
owner: debian:debian - [sed, -i, '/^%sudo/s/ALL$/NOPASSWD:ALL/', /etc/sudoers]
permissions: '0755'
content: | # Create log directory
#!/bin/bash - [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 set -e
echo "Starting first-boot setup as debian user..." 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 # Clone repository
cd /home/debian cd /home/debian
echo "Cloning GRCon23Tutorial repository..." echo "Cloning GRCon23Tutorial repository..."
@@ -103,85 +96,41 @@ write_files:
chmod +x install.sh chmod +x install.sh
./install.sh ./install.sh
cat > ~/start-sway.sh << 'LAUNCHEREOF' # Source conda and start Jupyter Lab
#!/bin/bash echo "Setting up conda environment and starting Jupyter Lab..."
# Start a bare X server with a virtual display source "/home/debian/conda/etc/profile.d/conda.sh"
Xorg :10 -ac -screen 1024x768 & conda activate GRCon23
XPID=$! jupyter-lab --ip=0.0.0.0 --port=8888 --no-browser &
# Set the DISPLAY environment variable for the new X server JUPYTER_PID=$!
export DISPLAY=:10 echo $JUPYTER_PID > /tmp/jupyter.pid
# Wait for X to be ready, then start Sway using XWayland echo "Jupyter Lab started with PID: $JUPYTER_PID"
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"
echo "First-boot setup completed!" echo "First-boot setup completed!"
echo "Installed packages:" echo "Jupyter Lab running on port 8888"
dpkg -l git firefox-esr sway mesa-vulkan-drivers | grep ^ii '
# Create marker file # Create marker file
sudo touch /etc/vm-initialized - [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
- [echo, "VM setup completed at $(date)", ">>", /var/log/vm-init.log] - [echo, "VM setup completed at $(date)", ">>", /var/log/vm-init.log]
- [echo, "User groups:", ">>", /var/log/vm-init.log] - [echo, "Jupyter Lab should be running on port 8888", ">>", /var/log/vm-init.log]
- [groups, debian, ">>", /var/log/vm-init.log]
# Final message # Final message
final_message: | final_message: |
VM initialization complete! VM initialization complete!
For Sway/Wayland to work: Setup completed:
1. The VM needs GPU acceleration 1. Git cloned GRCon23Tutorial repository
2. User 'debian' added to video, render, seat groups 2. Ran ./install.sh
3. seatd service enabled for Wayland sessions 3. Started Jupyter Lab on port 8888
Login with: Access:
Username: debian SSH: ssh debian@localhost -p 2222
Password: nixos Password: nixos
Jupyter Lab: http://localhost:8888 (forwarded from VM port 8888)
To start Sway manually: Check status in VM:
sway --unsupported-gpu sudo journalctl -u cloud-init
cat /var/log/vm-init.log
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.
EOF EOF
# Create cloud-init ISO # Create cloud-init ISO
@@ -190,10 +139,15 @@ EOF
"${vmDataDir}/user-data" "${vmDataDir}/user-data"
echo "VM files created in ${vmDataDir}" 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" '' runScript = pkgs.writeShellScriptBin "run-debian-vm" ''
set -e set -e
@@ -207,42 +161,33 @@ EOF
sleep 2 sleep 2
fi fi
echo "Starting Debian VM with GPU acceleration..." echo "Starting Debian VM..."
echo "" echo ""
echo "GPU/Display configuration:" echo "First boot will:"
echo "- Using virtio-gpu-pci with OpenGL" echo "1. Clone GRCon23Tutorial repository"
echo "- User added to video, render groups" echo "2. Run ./install.sh"
echo "- Mesa Vulkan drivers installed" echo "3. Start Jupyter Lab on port 8888"
echo "- seatd service enabled for Wayland"
echo "" echo ""
echo "After boot, to start Sway:" echo "Access after boot:"
echo " SSH: ssh debian@localhost -p 2222" echo " SSH: ssh debian@localhost -p 2222"
echo " Password: nixos" echo " Jupyter: http://localhost:8888"
echo " Then run: dbus-run-session sway" echo " Password for 'debian' user: nixos"
echo " Or: sway --unsupported-gpu"
echo "" 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 \ ${pkgs.qemu_kvm}/bin/qemu-kvm \
-name "Debian-GRCon-VM" \ -name "Debian-GRCon-VM" \
-machine q35,accel=kvm \ -machine accel=kvm \
-cpu host,-hypervisor \ -cpu host \
-smp 4 \ -smp 2 \
-m 4096 \ -m 2048 \
-drive file="${vmDataDir}/debian-persistent.qcow2",format=qcow2,if=virtio \ -drive file="${vmDataDir}/debian-persistent.qcow2",format=qcow2,if=virtio \
-drive file="${vmDataDir}/cloud-init.iso",format=raw,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 \ -device virtio-net-pci,netdev=n1 \
# GPU CONFIGURATION: -display gtk \
-device virtio-vga-gl \ -vga virtio \
-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 \
"$@" "$@"
''; '';