From 9a7bad2c178c6b4642ed50e7d10e69d03dc3e35b Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 7 Mar 2017 03:50:37 +0100 Subject: [PATCH] networkmanager service: support changing the mac-address (#23464) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Set `networking.networkmanager.wifi.macAddress` or `networking.networkmanager.ethernet.macAddress` to one of these values to change your macAddress. * "XX:XX:XX:XX:XX:XX": set the MAC address of the interface. * "permanent": use the permanent MAC address of the device. * "preserve": don’t change the MAC address of the device upon activation. * "random": generate a randomized value upon each connect. * "stable": generate a stable, hashed MAC address. See https://blogs.gnome.org/thaller/2016/08/26/mac-address-spoofing-in-networkmanager-1-4-0/ for more information --- .../services/networking/networkmanager.nix | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/nixos/modules/services/networking/networkmanager.nix b/nixos/modules/services/networking/networkmanager.nix index c11d4434c20..7255ffc5af4 100644 --- a/nixos/modules/services/networking/networkmanager.nix +++ b/nixos/modules/services/networking/networkmanager.nix @@ -24,6 +24,8 @@ let [connection] ipv6.ip6-privacy=2 + ethernet.cloned-mac-address=${cfg.ethernet.macAddress} + wifi.cloned-mac-address=${cfg.wifi.macAddress} ''; /* @@ -73,6 +75,19 @@ let "pre-down" = "pre-down.d/"; }; + macAddressOpt = mkOption { + type = types.either types.str (types.enum ["permanent" "preserve" "random" "stable"]); + default = "preserve"; + example = "00:11:22:33:44:55"; + description = '' + "XX:XX:XX:XX:XX:XX": MAC address of the interface. + permanent: use the permanent MAC address of the device. + preserve: don’t change the MAC address of the device upon activation. + random: generate a randomized value upon each connect. + stable: generate a stable, hashed MAC address. + ''; + }; + in { ###### interface @@ -140,6 +155,9 @@ in { ''; }; + ethernet.macAddress = macAddressOpt; + wifi.macAddress = macAddressOpt; + dispatcherScripts = mkOption { type = types.listOf (types.submodule { options = { @@ -229,6 +247,7 @@ in { systemd.services."network-manager" = { wantedBy = [ "network.target" ]; + restartTriggers = [ configFile ]; preStart = '' mkdir -m 700 -p /etc/NetworkManager/system-connections