When immediately bootstrapping a config like I do with my WSL 2 - Distro, you don’t need to update the system using channels (despite the welcome message telling you)!
Set it as the default
If you don’t have any other distro installed, you won’t have to do anything.
If you do, however, and want to use the NixOS distro by default, just run the following
wsl.exe --set-default NixOS
Nix(OS) & Home-Manager config
I have my own dendritic nix-config that manages my complete system and home level configuration for different hosts, users, etc.
Tip
This completely replaces any manual configuration I previously did in my Dotfiles setup.
Bootstrap
Rebuild the boot instead of directly switching to it
This should not be necessary if the WSL Settings are set correctly.
Modern Windows 11 installations should include the WSL Settings application, where you can manage the %USERPROFILE%\.wslconfig file graphically.
Make sure that the automatic proxy configuration under the Network tab is turned on.
Alternatively, especially if you’re on an older WSL version, where this option isn’t enabled by default, you can simply modify the %USERPROFILE\.wslconfig to include autoProxy=true under the [wsl] section.
You therefore only need to follow the WSL 2 - Distro section down below once while bootstrapping.
After that my config sets correct env_keep values.
To circumvent this, we (redundantly) export local environment variables first:
Unfortunately there is only a limited set of environment variables which get copied over by sudo!
This might be wise from a security standpoint but is annoying in this case.
To circumvent this, add --preserve-env=http_proxy,https_proxy,HTTP_PROXY,HTTPS_PROXY, or even simpler -E (which preserves all of the user’s environment variables, which is fine for this one-time usage) as an argument to sudo:
This should run without problem and the proxy environment variables should be correctly set now and after reboots, together with the env_keep configuration of sudo, so you can emit the -E flag down the line.