home

My NixOS systems configurations.
Log | Files | Refs | LICENSE

commit d22098bf6ec601855f676aedc18579488cb8d696
parent 949ad1a7ffdba3d1d0caad0da416717a5adb3048
Author: Vincent Demeester <vincent@sbr.pm>
Date:   Wed,  1 Jun 2022 14:59:01 +0200

profiles.desktop: networkmanager dispatch scripts…

… to make ethernet and wifi mutually exclusive.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Diffstat:
Msystems/modules/profiles/desktop.nix | 37+++++++++++++++++++++++++++++++++----
1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/systems/modules/profiles/desktop.nix b/systems/modules/profiles/desktop.nix @@ -55,11 +55,40 @@ in "interface-name:br-*" "interface-name:ve-*" "interface-name:veth*" - "interface-name:wg0" - "interface-name:docker0" - "interface-name:virbr*" - ]; # FIXME: add unmanaged depending on profiles (wg0, docker0, …) + ] + # Do not manager wireguard + ++ lib.optionals config.networking.wireguard.enable [ "interface-name:wg0" ] + # Do not manage docker interfaces + ++ lib.optionals config.virtualisation.docker.enable [ "interface-name:docker0" ] + # Do not manager libvirt interfaces + ++ lib.optionals config.virtualisation.libvirtd.enable [ "interface-name:virbr*" ]; packages = with pkgs; [ networkmanager-openvpn ]; + dispatcherScripts = [{ + # https://askubuntu.com/questions/1271491/disable-wifi-if-lan-is-connected + source = pkgs.writeText "wifi-wired-exclusive" '' + #!${pkgs.bash}/bin/bash + export LC_ALL=C + + enable_disable_wifi () + { + result=$(nmcli dev | grep "ethernet" | grep -w "connected") + if [ -n "$result" ]; then + nmcli radio wifi off + else + nmcli radio wifi on + fi + } + + if [ "$2" = "up" ]; then + enable_disable_wifi + fi + + if [ "$2" = "down" ]; then + enable_disable_wifi + fi + ''; + type = "basic"; + }]; }; services = {