Fedora
In this part, we’re setting up Fedora as our WSL distribution.
Info
Please also refer to Fedora’s official documentation
Install
Microsoft Store
If you can use the Microsoft Store, installing the Fedora distribution is as easy as installing the Fedora 42 app from the store.
Command line
wsl.exe --install FedoraLinux-42Tar-based
Download the tarball from koji, then check your WSL version
wsl.exe --versionInfo
The following part is mostly copy/pasted from the official documentation.
Version >= 2.4.4
- From the command line, install the tarball with
wsl --install --from-file .\path\to\Fedora.tar.xz
wsl.exe --install --from-file .\Fedora-WSL-Base-VERSION.x86_64.tar.xz - Enter the environment by running
wsl.exe -d Fedora- When prompted, provide a username. This will be the default user, and it will be added to the groups for
sudousage.
Version < 2.4.4
(These steps assume you are using PowerShell)
- Make a directory for the Fedora distribution with
mkdir $ENV:LOCALAPPDATA\WSL\Fedora- Import the WSL tarball with
wsl.exe --import Fedora $ENV:LOCALAPPDATA\WSL\Fedora .\Fedora-WSL-Base-VERSION.x86_64.tar.xz - Enter the environment with
wsl.exe -d Fedora -u root- Manually run
/usr/libexec/wsl/oobe.shto create the default user exitthe environment logged in as root- Enter the environment as the newly created user with
wsl.exe -d Fedora -u usernameSet a password
Make sure to set a password for the newly created user. This should be self-explanatory from a security standpoint.
From within WSL, do
sudo passwd usernameSet 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 Fedora distro by default, just run the following
wsl.exe --set-default FedoraLinux-42Just Works™?
Note
This should only be neccessary if you’re behind a (corporate) proxy.
As I’m sitting behind a corporate http proxy, I initially had no access to the internet.
This can be confirmed by running
curl https://fedoraproject.orgTo make WSL proxy-aware, I needed to
- Add the exports to the
~/.bashrc
PROXY_URL="http://<hostname>:<port>"
export all_proxy="$PROXY_URL"
export http_proxy="$PROXY_URL"
export https_proxy="$PROXY_URL"
export ftp_proxy="$PROXY_URL"
export no_proxy="127.0.0.1,0.0.0.0,localhost"
export ALL_PROXY="$PROXY_URL"
export HTTP_PROXY="$PROXY_URL"
export HTTPS_PROXY="$PROXY_URL"
export FTP_PROXY="$PROXY_URL"
export NO_PROXY="$no_proxy"- Source it
source ~/.bashrc- Allow
sudoto pass these environment variables through by setting theenv_keepproperty in/etc/sudoers.d/proxy
Defaults env_keep += "all_proxy http_proxy https_proxy ftp_proxy no_proxy ALL_PROXY HTTP_PROXY HTTPS_PROXY FTP_PROXY NO_PROXY"Rerunning the curl-command should now produce a response, and your system should update just fine.
NixOS
In this part, we’re setting up NixOS as our WSL distribution.
Info
Please also refer to the Official NixOS-WSL documentation.
Install
First download the latest nixos.wsl from the NixOS-WSL GitHub release page.
Simply double click the file or run
wsl.exe --install --from-file nixos.wslReplace
nixos.wsl: Path to your downloadednixos.wsl
Afterwards you get dropped into NixOS.
Tip
When immediately bootstrapping a config like I do with my Nix(OS) & Home-Manager config, 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 NixOSNix(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
bootinstead of directlyswitching to itsudo nixos-rebuild boot --flake github:DustVoice/nix-config#hostname
Replace
hostname: The machine’s hostname, defined inmodules/my/hosts
-
Exit the WSL shell and terminate the distro
wsl.exe -t NixOS -
Start a shell as the
rootuser and immediately exit, applying the new generationwsl.exe -d NixOS --user root exit -
Stop the distro again
wsl.exe -t NixOS -
Finally open a WSL shell with (hopefully) everything applied.
NOTE
This of course doesn’t transfer any files from the
nixosuser’s home directory to the newly created user!
Just Works™?
Note
This should only be neccessary if you’re behind a (corporate) proxy.
As I’m sitting behind a corporate http proxy, I initially had no access to the internet.
This can be confirmed by running
curl https://nixos.orgAnother symptom is that the previous bootstrap command hangs indefinitely.
To circumvent this, we (redundantly) export local environment variables first:
proxy_url="PROXY-URL"
export http_proxy="$proxy_url"
export https_proxy="$proxy_url"
export HTTP_PROXY="$proxy_url"
export HTTPS_PROXY="$proxy_url"
export CURL_NIX_FLAGS="-x $proxy_url"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 as an argument to sudo:
Modified bootstrap command
sudo --preserve-env=http_proxy,https_proxy,HTTP_PROXY,HTTPS_PROXY,CURL_NIX_FLAGS nixos-rebuild switch --flake github:DustVoice/nix-config#hostname
Replace
hostname: The machine’s hostname, defined inmodules/my/hosts
This should run without problem and the proxy environment variables should be correctly set now and after reboots.