Windows

WSL - Arch Linux

Install Arch Linux, set up a user account, and packages with nix.

Update wsl to the latest version.

Terminal
wsl --update

List available distributions.

Terminal
wsl --list --online

even if archlinux is not listed, you can still install it.

Install Arch Linux.

Terminal
wsl --install -d archlinux

Set the root password.

Terminal
passwd

Update the system

Update the package database and upgrade all packages.

Terminal
pacman -Syu

Stop Arch Linux and reopen it.

Run this in PowerShell or Command Prompt or Git Bash:

Terminal
wsl.exe --terminate archlinux

Install sudo

Install some basic packages.

Terminal
pacman -S sudo

Create a new user

It is not recommended to log in as the root all the time. You need a regular user who can run administrative commands when needed.

In Arch Linux, you can use the useradd command, to create a new user. Let's create a new user called “team”.

Terminal
useradd -m -G wheel iancleary

Here, the -m option will automatically create a home directory for the user at /home/.

Set the password for the new user.

Terminal
passwd iancleary

Add the new user to the wheel group.

Terminal
usermod -aG wheel iancleary

Edit the sudoers file to allow members of the wheel group to use sudo.

Terminal
sudo pacman -S nano
Terminal
EDITOR=nano visudo

Uncomment the following line by removing the # at the beginning of the line.

It is near the bottom of the file.

Terminal
%wheel ALL=(ALL) ALL

Save the document using CTRL + O and exit using CTRL + X.

At this point, you can just terminate the system using the command:

Terminal
wsl.exe --terminate archlinux

Update the wsl.conf file

Edit the wsl.conf file to set some options for WSL.

Terminal
sudo nano /etc/wsl.conf

Add the following content to the file:

...

[user]
default=iancleary

Save the document using CTRL + O and exit using CTRL + X.

Terminate the system using the command:

Terminal
wsl.exe --terminate archlinux

Now when you start Arch Linux, it will log you in as the user “iancleary”.

Windows Terminal Settings

Icon

https://wiki.archlinux.org/extensions/ArchLinux/modules/archnavbar/archicon.svg
{
  "colorScheme": "Tango Dark",
  "font": {
    "face": "MesloLGS NF"
  },
  "hidden": false,
  "name": "Arch Linux",
  "source": "Microsoft.WSL"
}

Update locale

Terminal
sudo nano /etc/locale.conf

Add the following content to the file:

LC_CTYPE="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
LANG="en_US.UTF-8"

Save the document using CTRL + O and exit using CTRL + X.

Stop Arch Linux and reopen it.

Terminal
wsl.exe --terminate archlinux

Run locale command to verify the changes.

Terminal
locale-gen

Stop Arch Linux and reopen it.

Terminal
wsl.exe --terminate archlinux

Setup Nix

Terminal
# Install git, curl and xz (e.g. for archlinux)
sudo pacman -S git xz curl less

# git is for general use and for cloning this repository
# xz is for decompression
# curl is for downloading nix installation script
# less is for git diff viewing (for use later)

# Clone my home/wsl config repository
git clone https://github.com/iancleary/wsl-config.git
cd wsl-config

# Install nix (determinate-systems installation)
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install

# Open tempoary shell with nix and home-manager (shell.nix)
# if no flake.lock exists, run `nix flake update`
# if 755 permission error, restart windows
nix-shell

# Remove nix (this is necessary, so home-manager can install nix)
nix-env -e nix

# Install the configuration (adjust to the configuration/hostname you want to use )
home-manager switch --flake .#windows-tower
home-manager switch --flake .#framework

# Exit temporary shell
exit

# Set zsh (installed by nix) as default shell
echo ~/.nix-profile/bin/zsh | sudo tee -a /etc/shells
sudo usermod -s ~/.nix-profile/bin/zsh $USER

# setup rust (rustup and gcc)
sudo pacman -S gcc
rustup default stable

# Install python and make (needed for some npm packages post install scripts, such as better-sqlite3)
sudo pacman -S python make

# sudo apt install python-is-python3 make

# gcc is needed for cargo run to properly install crates
# rustup is installed via the the nix flake iancleary/terminal-config
# rustup default stable (change stable to whatever channel you want)

Install ssh

Terminal
sudo pacman -S openssh

Create an ssh key if you wish.

GitHub's instructions

voila!

You now have Arch Linux running in WSL with a user account and sudo privileges.

You can install additional packages using pacman or your nix-config as needed.

WSL Set default

To set Arch Linux as the default distribution, run the following command in PowerShell or Command Prompt or Git Bash:

Terminal
wsl --set-default archlinux

If you need to list all installed distributions, run:

Terminal
wsl --list --verbose