Get up to speed with NixOS on WSL2 with the VSCode Nix IDE.
In principle very similar to nixos-wsl-starter, but this one is focused on VSCode development.
🏃 Clone this repo.
🏃 Download the WSL compatible tar.gz
at NixOS-WSL to the root of the cloned repo.
🏃 Install WSL (if not installed yet):
wsl --install
🏃 Import the tar.gz
into the OS folder in this repo:
wsl --import NixOS ./OS nixos-wsl.tar.gz --version 2
🏃 Set as default distro and get the shell:
wsl -s NixOS #default distribution
wsl -d NixOS #get a shell
🏃 Rebuild with the included flake (using this path notation to support git integration):
sudo nixos-rebuild --flake path://$PWD/Config/.#myhostyolo switch -L
The first time you rebuild you get a Error: Failed to open dbus connection
message because it actually upgraded NixOS as well, this is expected.
🏃 Enter your IDE environment in NixOS with Command Palette: WSL: Reopen Folder in WSL
and select NixOS
.
🏃 Install the recommended VSCode extensions as requested in the pop-up message. (this is a one time install, it actually preserves the extensions on reboot/rebuilds)
🏁🏁🏁 You're done (or ready for action) ! 🏁🏁🏁
🏃 Go back with Command Palette: WSL: Reopen Folder in Windows
.
🏃 Clean up old generations and artifacts:
sudo nix-collect-garbage --delete-old
🏃 Complete teardown:
wsl --unregister NixOS
Arion is a tool for building and running applications that consist of multiple docker containers using NixOS modules.
🏃 Configure WSL globally to free up port 53 (DNS), use the following configuration:
[wsl2]
localhostForwarding = true
networkingMode = NAT
dnsProxy = true
firewall = true
dnsTunneling = false
🏃 Reboot NixOS and start the container(s):
cd ./config
sudo arion up -d
sudo arion logs -f
🏃 Open dozzle:
🏃 Use CoreDNS via TCP, since UDP traffic isn't supported on WSL2. Run this on your host:
nslookup -vc nu.locali 127.0.0.1
This should return the following, as specified by the Corefile:
Name: nu.locali
Address: 127.0.0.1
🏃 Get the WSL2 shell again:
wsl -d NixOS #get a shell
🏃 Clone erwinkramer/nixos-on-azure, this repo is forked from rudesome/nixos-on-azure but I added Arion as a NixOS module with dozzle.
🏃 Follow the steps specified in the README of nixos-on-azure
.
🏃 Now manage your fleet! Try:
- OpenTofu with the nixos-anywhere/nixos-rebuild module to rebuild and update your VMs.
- Or try comin for GitOps (supports private GitHub and GitLab repo's).
- Or choose any other deployment tool.
VSCode extensions ideally should be installed via NixOS itself, but no native way is found. Please see discussion @ discourse.nixos.org as well.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.