Wlan with wpa_supplicant under NixOS?

Solution 1:

I doubt it will become any more informative than what you already have, yet here we go.

First we need to store our WPA2-PSK secrets:

       wpa_passphrase MyWifiSSID MySecretPassword > wpa_supplicant.conf

Now make sure you have stopped a Network Manager, if you use one, and issue all the following commands as sudo. We clean the interface (I call it wlan0):

        ip link set dev wlan0 down
        ip addr flush dev wlan0
        ip link set dev wlan0 up

Now we associate to the AP:

         wpa_supplicant -B -i wlan0 -Dnl80211 -c wpa_supplicant.conf
         dhclient wlan0

If the network is correctly configured, then you are done. If there are some errors in the DHCP configuration, you may be missing either the default gateway or the DNS servers. You can set them just as I am about to do in the case of a static IP.

If you do not have a DHCP server, or if you wish to give yourself a static IP (say, 192.168.1.200), then skip the last command above, and issue instead

         ip addr add 192.168.1.200/24 dev wlan0

Remember, 24 is the network mask in CIDR notation. If yours differs, please adjust accordingly. Once this is done, you will need a default gateway:

         ip route add default via 192.168.1.1 dev wlan0

where 192.168.1.1 is the address of your home router/gateway, and DNS servers,

         echo nameserver 8.8.8.8 >> /etc/resolv.conf
         echo nameserver 8.8.4.4 >> /etc/resolv.conf

This is it.