dotfiles/nixos/systems/omen/networking.nix

109 lines
2.5 KiB
Nix
Raw Normal View History

{
pkgs,
lib,
inputs',
secret,
notnft,
...
}: let
inherit
(lib)
concatStringsSep
;
in {
systemd.network.enable = true;
networking = {
hostName = "omen";
hostId = "10c7ffc5";
firewall.enable = false;
wireguard.interfaces."wg0" =
secret.wireguard."omen" or {privateKey = "";};
useDHCP = false;
};
services.networkd-dispatcher = {
enable = true;
rules.wlan-eth-switch = {
onState = ["no-carrier" "configured"];
script = ''
#!${pkgs.runtimeShell}
export PATH=$PATH:${pkgs.iwd}/bin
echo "entered state: '$STATE' on interface '$IFACE' with IPs '$IP_ADDRS'"
case $IFACE in
eth0|eth1)
echo $IP_ADDRS | ${lib.getExe' pkgs.grepcidr "grepcidr"} ${secret.network.networks.home.amsterdam or ""} > /dev/null
home_net=$?
case $STATE in
no-carrier)
if [ "$(iwctl station wlan0 show | grep -i State | tr -s ' ' | cut -f 3 -d ' ')" == "disconnected" ] ; then
iwctl device wlan0 set-property Powered off
iwctl device wlan0 set-property Powered on
fi
;;
configured)
if [ "$home_net" == "0" ] ; then
iwctl station wlan0 disconnect
fi
;;
*)
;;
esac
;;
*)
;;
esac
'';
};
};
systemd.network.links."50-eth0" = {
matchConfig.MACAddress = secret.network.mac.usbc-omen or "";
linkConfig.Name = "eth0";
};
systemd.network.links."50-eth1" = {
matchConfig.MACAddress = secret.network.mac.usbc-2-omen or "";
linkConfig.Name = "eth1";
};
systemd.network.networks."50-eth" = {
matchConfig.Name = "eth?";
networkConfig.DHCP = "ipv4";
linkConfig.RequiredForOnline = "no";
extraConfig = ''
[DHCP]
UseDNS=false
'';
};
systemd.network.networks."50-wlan" = {
matchConfig.Name = "wlan?";
networkConfig.DHCP = "ipv4";
extraConfig = ''
[DHCP]
UseDNS=false
'';
};
systemd.network.wait-online.enable = false;
services.resolved.enable = true;
services.resolved.fallbackDns = lib.mkForce [];
networking.nameservers = lib.mkForce [
(secret.network.ips.blowhole.ip or "")
];
networking.wireless.iwd.enable = true;
hardware.bluetooth = {
enable = true;
settings = {
General.Enable = concatStringsSep "," ["Control" "Gateway" "Headset" "Media" "Sink" "Socket" "Source"];
};
};
}