NixOS, a unique Linux distribution known for its declarative configuration model, may pose some challenges for newcomers when it comes to connecting to Wi-Fi networks. However, with a little guidance, you can easily set up your wireless connection. This article will walk you through the steps to connect to Wi-Fi on NixOS.
Prerequisites
Before starting, ensure you have the following:
- NixOS Installed: Make sure you have NixOS installed and running on your machine.
- Wireless Adapter: Ensure your machine has a wireless adapter that is recognized by the NixOS kernel.
- NetworkManager (Optional): While not mandatory, having NetworkManager installed can simplify the process of managing your network connections.
Step 1: Identify Your Wireless Adapter
First, check if your wireless adapter is recognized by the system. Open your terminal and execute:
ip link
Look for a device that typically starts with wlan
(e.g., wlan0
). If you see it, that means your wireless adapter is recognized.
Step 2: Configure Your Wi-Fi in NixOS
Option A: Using NetworkManager (Recommended)
If you prefer to use NetworkManager, you first need to enable it in your NixOS configuration.
-
Edit your NixOS Configuration: Open your NixOS configuration file, usually located at
/etc/nixos/configuration.nix
:sudo nano /etc/nixos/configuration.nix
-
Enable NetworkManager: Add or uncomment the following lines:
networking.networkmanager.enable = true;
-
Rebuild the NixOS Configuration: Apply the changes by rebuilding your NixOS configuration:
sudo nixos-rebuild switch
-
Connect to Wi-Fi: After enabling NetworkManager, you can use a graphical interface or the command line to connect to a Wi-Fi network. If you're using a desktop environment, look for the NetworkManager applet in your system tray. For command line, use:
nmcli device wifi list nmcli device wifi connect YOUR_SSID password YOUR_PASSWORD
Option B: Using wpa_supplicant
If you prefer not to use NetworkManager or if it is not installed, you can connect using wpa_supplicant
.
-
Install wpa_supplicant: Ensure that
wpa_supplicant
is included in your NixOS configuration:networking.wpa_supplicant.enable = true;
-
Edit Configuration: Create or edit the
/etc/wpa_supplicant/wpa_supplicant.conf
file:sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Add the following lines, replacing
YOUR_SSID
andYOUR_PASSWORD
with your Wi-Fi network's credentials:network={ ssid="YOUR_SSID" psk="YOUR_PASSWORD" }
-
Rebuild Configuration: After saving your configuration, rebuild NixOS:
sudo nixos-rebuild switch
-
Connect to Wi-Fi: Start
wpa_supplicant
by running:sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
Replace
wlan0
with your actual wireless interface name. -
Obtain an IP Address: Finally, use
dhclient
to obtain an IP address:sudo dhclient wlan0
Step 3: Verify Connection
To confirm that you are successfully connected to your Wi-Fi network, you can run:
ping google.com
If you receive replies, you are connected to the internet.
Conclusion
Connecting to Wi-Fi on NixOS is straightforward once you know the steps involved. Whether you opt for the ease of NetworkManager or prefer the manual approach with wpa_supplicant
, you can get your system online efficiently. NixOS’s declarative approach means that your Wi-Fi settings will be reproducible, making network configuration simple and consistent across system rebuilds. Happy networking!