Sway not working, but proper init
AND a good monitoring one-liner
This commit is contained in:
@@ -19,7 +19,7 @@ nix-build vm.nix -A system.build.customVM
|
|||||||
```bash
|
```bash
|
||||||
ssh debian@localhost -p 2222
|
ssh debian@localhost -p 2222
|
||||||
# Inside VM after SSH
|
# Inside VM after SSH
|
||||||
cat /var/log/cloud-init-output.log
|
watch -n 1 "cat /var/log/cloud-init-output.log | tail"
|
||||||
cat /var/log/cloud-init.log
|
cat /var/log/cloud-init.log
|
||||||
ls -la /home/debian/
|
ls -la /home/debian/
|
||||||
```
|
```
|
||||||
|
|||||||
231
vm.nix
231
vm.nix
@@ -8,7 +8,7 @@ let
|
|||||||
debianImage = pkgs.fetchurl {
|
debianImage = pkgs.fetchurl {
|
||||||
name = "debian-13-genericcloud-amd64.qcow2";
|
name = "debian-13-genericcloud-amd64.qcow2";
|
||||||
url = "https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.qcow2";
|
url = "https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.qcow2";
|
||||||
hash = "sha256-V9a6DUghJB5j4Vz9Y5aikZ8syhx5Zn2593m8/8xNwIU="; # REPLACE THIS
|
hash = "sha256-V9a6DUghJB5j4Vz9Y5aikZ8syhx5Zn2593m8/8xNwIU=";
|
||||||
};
|
};
|
||||||
|
|
||||||
# 2. VM DATA DIRECTORY
|
# 2. VM DATA DIRECTORY
|
||||||
@@ -17,11 +17,11 @@ let
|
|||||||
# 3. CREATE ALL FILES IN A SCRIPT
|
# 3. CREATE ALL FILES IN A SCRIPT
|
||||||
setupScript = pkgs.writeShellScriptBin "setup-vm-files" ''
|
setupScript = pkgs.writeShellScriptBin "setup-vm-files" ''
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Create VM directory
|
# Create VM directory
|
||||||
mkdir -p "${vmDataDir}"
|
mkdir -p "${vmDataDir}"
|
||||||
|
|
||||||
# Create persistent disk if it doesn't exist
|
# Create persistent disk if it doesn't exist (with 20GB initial size)
|
||||||
if [ ! -f "${vmDataDir}/debian-persistent.qcow2" ]; then
|
if [ ! -f "${vmDataDir}/debian-persistent.qcow2" ]; then
|
||||||
echo "Creating persistent disk from base image..."
|
echo "Creating persistent disk from base image..."
|
||||||
${pkgs.qemu}/bin/qemu-img create -f qcow2 \
|
${pkgs.qemu}/bin/qemu-img create -f qcow2 \
|
||||||
@@ -30,52 +30,219 @@ let
|
|||||||
"${vmDataDir}/debian-persistent.qcow2" \
|
"${vmDataDir}/debian-persistent.qcow2" \
|
||||||
20G
|
20G
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create cloud-init configuration
|
# Create cloud-init configuration
|
||||||
cat > "${vmDataDir}/user-data" << 'EOF'
|
cat > "${vmDataDir}/user-data" << 'EOF'
|
||||||
#cloud-config
|
#cloud-config
|
||||||
password: nixos
|
# User configuration
|
||||||
chpasswd: { expire: False }
|
users:
|
||||||
ssh_pwauth: True
|
- name: debian
|
||||||
runcmd:
|
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||||
- |
|
groups: sudo, users, adm, video, render
|
||||||
if [ ! -f /etc/vm-initialized ]; then
|
shell: /bin/bash
|
||||||
cd /home/debian
|
lock_passwd: false
|
||||||
sudo -u debian git clone https://github.com/someone/something
|
passwd: nixos
|
||||||
cd something
|
system: false
|
||||||
chmod +x install.sh
|
create_groups: true
|
||||||
sudo -u debian ./install.sh
|
|
||||||
touch /etc/vm-initialized
|
# Enable password authentication
|
||||||
fi
|
ssh_pwauth: true
|
||||||
EOF
|
chpasswd:
|
||||||
|
expire: false
|
||||||
|
list: |
|
||||||
|
debian:nixos
|
||||||
|
root:nixos
|
||||||
|
|
||||||
|
# Update system
|
||||||
|
package_update: true
|
||||||
|
package_upgrade: true
|
||||||
|
|
||||||
|
# Install packages - ADDED GPU DRIVERS
|
||||||
|
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
|
||||||
|
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..."
|
||||||
|
git clone https://github.com/ARDC-TOBB-ETU/GRCon23Tutorial --depth=1
|
||||||
|
|
||||||
|
# Run installation
|
||||||
|
cd GRCon23Tutorial
|
||||||
|
echo "Running installation script..."
|
||||||
|
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"
|
||||||
|
|
||||||
|
echo "First-boot setup completed!"
|
||||||
|
echo "Installed packages:"
|
||||||
|
dpkg -l git firefox-esr sway mesa-vulkan-drivers | grep ^ii
|
||||||
|
|
||||||
|
# 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
|
||||||
|
- [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]
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
Login with:
|
||||||
|
Username: debian
|
||||||
|
Password: nixos
|
||||||
|
|
||||||
|
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.
|
||||||
|
EOF
|
||||||
|
|
||||||
# Create cloud-init ISO
|
# Create cloud-init ISO
|
||||||
${pkgs.cloud-utils}/bin/cloud-localds \
|
${pkgs.cloud-utils}/bin/cloud-localds \
|
||||||
"${vmDataDir}/cloud-init.iso" \
|
"${vmDataDir}/cloud-init.iso" \
|
||||||
"${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"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# 4. LAUNCH SCRIPT
|
# 4. LAUNCH SCRIPT WITH GPU SUPPORT
|
||||||
runScript = pkgs.writeShellScriptBin "run-debian-vm" ''
|
runScript = pkgs.writeShellScriptBin "run-debian-vm" ''
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Run setup first
|
# Run setup first
|
||||||
${setupScript}/bin/setup-vm-files
|
${setupScript}/bin/setup-vm-files
|
||||||
|
|
||||||
# Launch QEMU with KVM acceleration
|
# Check if VM is already running
|
||||||
|
if pgrep -f "debian-persistent.qcow2" > /dev/null; then
|
||||||
|
echo "VM appears to be already running. Stopping it first..."
|
||||||
|
pkill -f "debian-persistent.qcow2"
|
||||||
|
sleep 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Starting Debian VM with GPU acceleration..."
|
||||||
|
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 ""
|
||||||
|
echo "After boot, to start Sway:"
|
||||||
|
echo " SSH: ssh debian@localhost -p 2222"
|
||||||
|
echo " Password: nixos"
|
||||||
|
echo " Then run: dbus-run-session sway"
|
||||||
|
echo " Or: sway --unsupported-gpu"
|
||||||
|
echo ""
|
||||||
|
echo "Press Ctrl+Alt+G to release mouse"
|
||||||
|
|
||||||
|
# Launch QEMU with GPU acceleration
|
||||||
${pkgs.qemu_kvm}/bin/qemu-kvm \
|
${pkgs.qemu_kvm}/bin/qemu-kvm \
|
||||||
-name "Debian-Persistent-VM" \
|
-name "Debian-GRCon-VM" \
|
||||||
-machine accel=kvm \
|
-machine q35,accel=kvm \
|
||||||
-cpu host \
|
-cpu host,-hypervisor \
|
||||||
-m 2048 \
|
-smp 4 \
|
||||||
|
-m 4096 \
|
||||||
-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 \
|
||||||
-device virtio-net-pci,netdev=n1 \
|
-device virtio-net-pci,netdev=n1 \
|
||||||
-display gtk \
|
# GPU CONFIGURATION:
|
||||||
-vga virtio \
|
-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 \
|
||||||
"$@"
|
"$@"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user