22# vi: set ft=ruby :
33
44Vagrant . configure ( "2" ) do |config |
5- # Basic VM Configuration
6- config . vm . box = "utm/ubuntu-24.04"
5+ # Use minimal ARM64 Ubuntu 24.04 box
6+ config . vm . box = "cloud-image/ubuntu-24.04"
7+
8+ # Increase boot timeout for QEMU
9+ config . vm . boot_timeout = 600
710 config . vm . hostname = "nix-dev"
811
9- # Forward a continuous port range
10- ( 3000 ..4000 ) . each do |port |
11- config . vm . network "forwarded_port" , guest : port , host : port
12- end
12+ # Port forwarding will be handled by QEMU provider settings
1313
14- # Fix SSH authentication issues
14+ # SSH configuration
1515 config . ssh . insert_key = true
1616 config . ssh . forward_agent = true
17-
18- # UTM Provider Configuration
19- config . vm . provider "utm" do |utm |
20- utm . name = "nix-dev-vm"
21- utm . memory = "8192"
22- utm . cpus = 6
17+
18+ # Forward a reasonable port range for development (20 ports)
19+ ( 3000 ..3019 ) . each do |port |
20+ config . vm . network "forwarded_port" , guest : port , host : port
21+ end
22+
23+ # QEMU Provider Configuration
24+ config . vm . provider "qemu" do |qemu |
25+ qemu . name = "nix-dev-vm"
26+ qemu . memory = "8192"
27+ qemu . cpus = 4
28+ qemu . arch = "aarch64"
29+ qemu . machine = "virt,accel=hvf"
30+ qemu . cpu = "host"
31+ qemu . net_device = "virtio-net-pci"
32+ # Just basic networking - no crazy port forwarding
33+ qemu . extra_qemu_args = %w( -display none )
34+ qemu . disk_size = "50G"
2335 end
2436
2537 # System provisioning script
@@ -65,7 +77,6 @@ Vagrant.configure("2") do |config|
6577 sh <(curl -L https://nixos.org/nix/install) --daemon
6678
6779 # Create system Nix configuration with experimental features
68- # This needs to be done RIGHT AFTER Nix installation
6980 sudo mkdir -p /etc/nix
7081 sudo bash -c 'cat > /etc/nix/nix.conf << EOL
7182experimental-features = nix-command flakes
7788 # Make sure ~/.config/nix directory exists
7889 mkdir -p $HOME/.config/nix
7990
80- # Restart the Nix daemon to apply settings BEFORE sourcing Nix
91+ # Restart the Nix daemon to apply settings
8192 sudo systemctl restart nix-daemon
8293
83- # NOW source Nix environment (after config has been created & daemon restarted)
94+ # Source Nix environment
8495 if [ -e /etc/profile.d/nix.sh ]; then
8596 . /etc/profile.d/nix.sh
8697 fi
8798
88- # Verify Nix is working with experimental features
99+ # Verify Nix is working
89100 echo "Checking Nix version and features..."
90101 nix --version
91- echo "Testing experimental features directly..."
92- nix-env --version # Should work without extra flags now
93102
94103 # Basic Git configuration
95104 git config --global init.defaultBranch main
96105 git config --global core.editor "vim"
97106
98- # Clone configuration with better handling for reprovisioning
99- echo "=== Setting up configuration ==="
100- mkdir -p $HOME/.config
101-
102- # Handle existing directory on reprovisioning
107+ # Clone your Nix configuration
108+ echo "=== Setting up Nix configuration ==="
103109 if [ -d "$HOME/.config/nix" ]; then
104110 echo "Found existing nix config directory, backing it up..."
105111 mv $HOME/.config/nix $HOME/.config/nix.bak.$(date +%s)
106112 fi
107113
108114 git clone --depth=1 https://github.com/svnlto/nix-config.git $HOME/.config/nix
109115
110- # Set proper permissions for the config directory
116+ # Set proper permissions
111117 sudo chown -R vagrant:vagrant $HOME/.config/nix
112-
113118 find $HOME/.config/nix -type d -exec chmod 755 {} \\ ;
114119 find $HOME/.config/nix -type f -exec chmod 644 {} \\ ;
115120
116- # Home Manager will replace this later
121+ # Setup minimal ZSH environment
117122 echo "Setting up minimal ZSH environment..."
118- # Ensure we can write to .zshenv
119123 rm -f $HOME/.zshenv
120124 cat > $HOME/.zshenv <<EOL
121125# Source Nix environment
@@ -128,78 +132,58 @@ EOL
128132 echo "Setting ZSH as default shell..."
129133 sudo chsh -s $(which zsh) vagrant
130134
131- # Create a minimal .zshrc to ensure the shell works
132- echo "Creating temporary .zshrc..."
133- # Ensure we can write to .zshrc
135+ # Create minimal .zshrc
134136 rm -f $HOME/.zshrc
135137 cat > $HOME/.zshrc <<EOL
136- # This is a temporary .zshrc that will be replaced by home-manager
137- # when you manually run: home-manager switch --flake ~/.config/nix#vagrant
138+ # Temporary .zshrc - will be replaced by home-manager
138139export PS1="%B%F{green}%n@%m%f:%F{blue}%~%f%(!.#.$)%b "
139140export PATH=\$ PATH:\$ HOME/.nix-profile/bin
140141EOL
141142 chmod 644 $HOME/.zshrc
142143
143- # Home Manager will be run AFTER the RAM disk setup in a separate provision step
144144 echo "=== Initial setup completed ==="
145- echo "RAM disk and configuration will be set up next"
146145 SHELL
147146
148- # Add a special provision step just for git cleanup
147+ # Git cleanup provision
149148 config . vm . provision "shell" , run : "always" , privileged : false , inline : <<-SHELL
150- # Ensure git repo stays clean by dealing with problematic files after home-manager runs
151149 if [ -L "$HOME/.config/nix/nix.conf" ] && [ -d "$HOME/.config/nix/.git" ]; then
152150 echo "=== Cleaning up git conflicts ==="
153151 cd "$HOME/.config/nix"
154-
155- # Reset git repo state
156152 git reset --hard HEAD
157153 fi
158154 SHELL
159155
160- # Initial RAM disk setup - handle everything here
156+ # RAM disk setup
161157 config . vm . provision "shell" , run : "always" , privileged : true , inline : <<-SHELL
162158 echo "=== Setting up RAM disk ==="
163159
164- # Unmount if already mounted but with issues
160+ # Unmount if already mounted
165161 if mount | grep -q "/ramdisk"; then
166- echo "Unmounting existing RAM disk to ensure clean setup ..."
162+ echo "Unmounting existing RAM disk..."
167163 umount /ramdisk 2>/dev/null || true
168164 fi
169165
170- # Ensure base directory exists with correct permissions
171- echo "Creating RAM disk mount point..."
166+ # Create mount point
172167 rm -rf /ramdisk 2>/dev/null || true
173168 mkdir -p /ramdisk
174169 chmod 1777 /ramdisk
175170
176- # Mount fresh RAM disk
171+ # Mount RAM disk
177172 echo "Mounting RAM disk..."
178173 mount -t tmpfs -o size=2G,mode=1777 none /ramdisk
179- if mount | grep -q "/ramdisk"; then
180- echo "RAM disk successfully mounted"
181- else
182- echo "ERROR: Failed to mount RAM disk"
183- exit 1
184- fi
185174
186- # Create the necessary directories and set permissions
187- echo "Setting up RAM disk directories and permissions..."
175+ # Create directories
188176 mkdir -p /ramdisk/.npm /ramdisk/tmp /ramdisk/.terraform.d/plugin-cache /ramdisk/.pnpm/store
189177 chmod 1777 /ramdisk/tmp
190- chmod 1777 /ramdisk # Ensure the base directory is writable by all
191178 chmod 777 /ramdisk/.npm /ramdisk/.terraform.d /ramdisk/.pnpm
192179
193- # Make sure everything is owned by the vagrant user
180+ # Set ownership
194181 chown -R vagrant:vagrant /ramdisk
195182
196- # Verify permissions
197- echo "Verifying permissions..."
198- ls -la /ramdisk
199-
200183 echo "RAM disk setup complete"
201184 SHELL
202185
186+ # Home Manager setup
203187 config . vm . provision "shell" , run : "always" , privileged : false , inline : <<-SHELL
204188 echo "=== Running home-manager setup ==="
205189
@@ -208,32 +192,25 @@ EOL
208192 . /etc/profile.d/nix.sh
209193 fi
210194
211- echo "Checking RAM disk status..."
212- ls -la /ramdisk
213-
214- # Now run home-manager with RAM disk available
195+ # Run home-manager
215196 echo "Running home-manager switch command..."
216197 NIXPKGS_ALLOW_UNFREE=1 nix run home-manager/master -- switch -b backup.$RANDOM --flake ~/.config/nix#vagrant --impure || {
217198 echo "Home Manager switch failed. See above for errors."
218199 }
219200 SHELL
220201
202+ # Final status
221203 config . vm . provision "shell" , run : "always" , privileged : false , inline : <<-SHELL
222204 echo ""
223205 echo "=== Development environment ready ==="
224- echo "The VM has been set up with Nix and tools."
225- echo ""
226- echo "Connect to the VM using:"
227- echo " vagrant ssh"
206+ echo "Connect to the VM using: vagrant ssh"
228207 echo ""
229208
230209 if [ -f "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" ]; then
231- echo "Home Manager has been successfully configured !"
210+ echo "✅ Home Manager configured successfully!"
232211 else
233- echo "NOTE: Home Manager setup didn't complete successfully."
234- echo "To manually run the home-manager setup:"
235- echo " nix run home-manager/master -- switch -b backup.$(date +%s) --flake ~/.config/nix#vagrant --impure"
236- echo ""
212+ echo "⚠️ Home Manager setup incomplete. To retry manually:"
213+ echo " nix run home-manager/master -- switch --flake ~/.config/nix#vagrant --impure"
237214 fi
238215 SHELL
239- end
216+ end
0 commit comments