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-42

Tar-based

Download the tarball from koji, then check your WSL version

wsl.exe --version

Info

The following part is mostly copy/pasted from the official documentation.

Version >= 2.4.4
  1. 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 
  1. Enter the environment by running
wsl.exe -d Fedora
  1. When prompted, provide a username. This will be the default user, and it will be added to the groups for sudo usage.
Version < 2.4.4

(These steps assume you are using PowerShell)

  1. Make a directory for the Fedora distribution with
mkdir $ENV:LOCALAPPDATA\WSL\Fedora
  1. Import the WSL tarball with
wsl.exe --import Fedora $ENV:LOCALAPPDATA\WSL\Fedora .\Fedora-WSL-Base-VERSION.x86_64.tar.xz 
  1. Enter the environment with
wsl.exe -d Fedora -u root
  1. Manually run /usr/libexec/wsl/oobe.sh to create the default user
  2. exit the environment logged in as root
  3. Enter the environment as the newly created user with 
wsl.exe -d Fedora -u username

Set 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 username

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 Fedora distro by default, just run the following

wsl.exe --set-default FedoraLinux-42

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://fedoraproject.org

To make WSL proxy-aware, I needed to

  1. Add the exports to the ~/.bashrc
~/.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"
  1. Source it
source ~/.bashrc
  1. Allow sudo to pass these environment variables through by setting the env_keep property in /etc/sudoers.d/proxy
/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.wsl

Replace

  • nixos.wsl: Path to your downloaded nixos.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 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

  1. Rebuild the boot instead of directly switching to it

    sudo nixos-rebuild boot --flake github:DustVoice/nix-config#hostname

Replace

  1. Exit the WSL shell and terminate the distro

    wsl.exe -t NixOS
  2. Start a shell as the root user and immediately exit, applying the new generation

    wsl.exe -d NixOS --user root exit
  3. Stop the distro again

    wsl.exe -t NixOS
  4. Finally open a WSL shell with (hopefully) everything applied.

NOTE

This of course doesn’t transfer any files from the nixos user’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.org

Another 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

This should run without problem and the proxy environment variables should be correctly set now and after reboots.