Declarative wifi configuration

I’d like to make my computer connect to my wifi automatically. Is this possible to do through configuration.nix? There seems to be options in networking related to it, but I cannot figure it out. Preferably the wifi password would be stored in a separate file so the configuration can be versioned.


We have a way but it requires the password in the configuration and not externally: NixOS 23.11 manual | Nix & NixOS


Thanks, must have missed that section in manual.

Can I also add a OpenVPN, with the VPN’s username and password, and also configure one of the Wi-Fi connections to automatically also connect to the VPN in the nixos config?

there is a new way to do this now which is networking.networkmanager.ensureProfiles and also allows for secret loading through files. It supports everything networkmanager supports, so wifi, openvpn, wireguard, ethernet, etc…


@Janik, thank you very much for your improvements!

1 Like

How do you securely configure a wifi name to be the contents of /run/secrets/home-wifi-name and the wifi password to be the contents of /run/secrets/home-wifi-password?