Compare commits

...

5 Commits

Author SHA1 Message Date
e5ae18155a Working version: Jupyter exposed on host
unattended install achieved !
2026-02-08 00:40:08 +02:00
c330054da6 removed reboot advice 2026-02-07 23:56:42 +02:00
8315388aee Sway not working, but proper init
AND a good monitoring one-liner
2026-02-07 23:53:51 +02:00
879194c05c Added instruction about rebooting the first time 2026-02-07 23:15:02 +02:00
198149fca0 Added cloudinit monitoring instructions 2026-02-07 23:14:05 +02:00
2 changed files with 147 additions and 28 deletions

View File

@@ -15,3 +15,10 @@ nix-build vm.nix -A system.build.customVM
```bash ```bash
./result/bin/run-debian-vm ./result/bin/run-debian-vm
``` ```
3. Watch it unravel:
```bash
ssh debian@localhost -p 2222
# Inside VM after SSH
watch -n 1 "cat /var/log/cloud-init-output.log | tail"
```
4. After a while, the Jupyter URL will spawn

148
vm.nix
View File

@@ -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
@@ -21,7 +21,7 @@ let
# 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 \
@@ -33,21 +33,105 @@ let
# 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
shell: /bin/bash
lock_passwd: false
passwd: nixos
system: false
create_groups: true
# Enable password authentication
ssh_pwauth: true
chpasswd:
expire: false
list: |
debian:nixos
root:nixos
# Update system
package_update: true
package_upgrade: true
# Install packages
packages:
- git
- curl
- wget
# 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
- | - |
if [ ! -f /etc/vm-initialized ]; then su - debian -c '
set -e
echo "Starting first-boot setup as debian user..."
# Clone repository
cd /home/debian cd /home/debian
sudo -u debian git clone https://github.com/someone/something echo "Cloning GRCon23Tutorial repository..."
cd something git clone https://github.com/ARDC-TOBB-ETU/GRCon23Tutorial --depth=1
# Run installation
cd GRCon23Tutorial
echo "Running installation script..."
chmod +x install.sh chmod +x install.sh
sudo -u debian ./install.sh ./install.sh
touch /etc/vm-initialized
fi # Source conda and start Jupyter Lab
EOF 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 "Jupyter Lab running on port 8888"
'
# Create marker file
- [touch, /etc/vm-initialized]
- [echo, "VM setup completed at $(date)", ">>", /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!
Setup completed:
1. Git cloned GRCon23Tutorial repository
2. Ran ./install.sh
3. Started Jupyter Lab on port 8888
Access:
SSH: ssh debian@localhost -p 2222
Password: nixos
Jupyter Lab: http://localhost:8888 (forwarded from VM port 8888)
Check status in VM:
sudo journalctl -u cloud-init
cat /var/log/vm-init.log
EOF
# Create cloud-init ISO # Create cloud-init ISO
${pkgs.cloud-utils}/bin/cloud-localds \ ${pkgs.cloud-utils}/bin/cloud-localds \
@@ -55,24 +139,52 @@ let
"${vmDataDir}/user-data" "${vmDataDir}/user-data"
echo "VM files created in ${vmDataDir}" echo "VM files created in ${vmDataDir}"
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 # 4. LAUNCH SCRIPT WITH PORT FORWARDING
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..."
echo ""
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 after boot:"
echo " SSH: ssh debian@localhost -p 2222"
echo " Jupyter: http://localhost:8888"
echo " Password for 'debian' user: nixos"
echo ""
echo "Press Ctrl+Alt+G to release mouse from VM window"
# Launch QEMU with port 8888 forwarded
${pkgs.qemu_kvm}/bin/qemu-kvm \ ${pkgs.qemu_kvm}/bin/qemu-kvm \
-name "Debian-Persistent-VM" \ -name "Debian-GRCon-VM" \
-machine accel=kvm \ -machine accel=kvm \
-cpu host \ -cpu host \
-smp 2 \
-m 2048 \ -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 \
-display gtk \ -display gtk \
-vga virtio \ -vga virtio \