You can also use Network Manager; this way you won’t have to specify the networks in your NixOS configuration, and Network Manager will connect automatically after sleep/reboot/etc. Jon Ringer’s answer is a visually pleasing intro.
The way I set it up:
-
In
/etc/nixos/configuration.nix
, I had to add my user to thenetworkmanager
group. The example from Chapter 7. User Management in the NixOS manual shows how:users.users.alice = { home = "/home/alice"; extraGroups = [ "wheel" "networkmanager" ]; # ... };
(Here’s the reference docs for
users.users.<your-username>.extraGroups
NixOS option.) -
Next (from Chris Martin’s Installing NixOS post):
Now you’ll want to turn on the network manager which can manage your WPA keys so you don’t have to keep manually messing with
wpa_supplicant
.Replace
networking.wireless.enable = true;
with
networking.networkmanager.enable = true;
Also add
kde4.networkmanagement
to the package list to get a GUI for it. -
sudo nixos-rebuild switch
Then the commands that I usually use:
nmcli device wifi list
nmcli device wifi connect "wifi-name" password 'password'
I use an old Lenovo T520 laptop, and the Network Manager sometimes acts up with different error messages every time after coming back from sleep or reboot, but then this usually helps:
sudo systemctl restart wpa_supplicant.service dhcpcd.service NetworkManager.service