NetworkManager

From NixOS Wiki
Revision as of 21:16, 5 August 2024 by Frontear (talk | contribs) (add some configuration options for NetworkManager)

NetworkManager is a program for configuring network devices on Linux. It is widely used by several Linux distributions and can be optionally enabled on NixOS for non-declarative network configuration. It also tends to be the default for many desktop environments, such as GNOME or KDE Plasma.

Installation

NetworkManager can be enabled in the NixOS configuration file with the following line:

networking.networkmanager.enable = true;

In order to allow access to the NetworkManager daemon and be able to configure and add new networks, the user must be added to the networkmanager group. This can be done through the extraGroups option for a defined user:

users.users.<name>.extraGroups = [ "networkmanager" ];

By default, NetworkManager comes with nmcli and nmtui as user interfaces, however, a GTK interface called nm-connection-editor can be found in the nm-applet package.

Usage

NetworkManager can be used with several front ends, such as nmcli, nmtui, or nm-applet and nm-connection-editor.

Configuration

The NixOS modules offer additional configurations that can be setup very easily.

DNS Management

To allow custom DNS management, you must disable NetworkManager's built-in DNS resolution, as well as some NixOS dhcp related options. Refer to the configuration below as an example of what to do:

networking.networkmanager.enable = true;

# Disable NetworkManager's internal DNS resolution
networking.networkmanager.dns = "none";

# These options are unnecessary when managing DNS ourselves
networking.useDHCP = false;
networking.dhcpcd.enable = false;

# Configure DNS servers manually (this example uses Cloudflare and Google DNS)
# IPv6 DNS servers can be used here as well.
networking.nameservers = [
  "1.1.1.1"
  "1.0.0.1"
  "8.8.8.8"
  "8.8.4.4"
];

Power Saving

On laptops, where extra power savings may be desired, you can enable NetworkManager specific power saving options as follows:

networking.networkmanager.wifi.powersave = true;

Please see Power Management for more tips relating to power-saving tips and tricks for NixOS.