System: Declaratively define networkmanager profiles
This commit is contained in:
@ -28,6 +28,7 @@ with mylib.networking; {
|
|||||||
network = {
|
network = {
|
||||||
inherit hostname;
|
inherit hostname;
|
||||||
enable = true;
|
enable = true;
|
||||||
|
useNetworkManager = true;
|
||||||
|
|
||||||
networks = {
|
networks = {
|
||||||
# Default wildcard ethernet network for all hosts
|
# Default wildcard ethernet network for all hosts
|
||||||
|
@ -16,9 +16,18 @@ in {
|
|||||||
services.resolved.enable = true;
|
services.resolved.enable = true;
|
||||||
services.resolved.llmnr = "false";
|
services.resolved.llmnr = "false";
|
||||||
|
|
||||||
|
# Use the programs.nm-applet instead
|
||||||
|
# environment.systemPackages = with pkgs;
|
||||||
|
# builtins.concatLists [
|
||||||
|
# []
|
||||||
|
# (lib.optionals cfg.useNetworkManager [networkmanagerapplet]) # This is started by hyprland if enabled
|
||||||
|
# ];
|
||||||
|
|
||||||
|
programs.nm-applet.enable = cfg.useNetworkManager;
|
||||||
|
|
||||||
# Main Networks
|
# Main Networks
|
||||||
systemd.network = {
|
systemd.network = {
|
||||||
enable = true;
|
enable = !cfg.useNetworkManager;
|
||||||
wait-online.timeout = 10;
|
wait-online.timeout = 10;
|
||||||
|
|
||||||
# Don't wait for all networks to be configured, as e.g. wg0 will only be upon manual activation
|
# Don't wait for all networks to be configured, as e.g. wg0 will only be upon manual activation
|
||||||
@ -36,7 +45,7 @@ in {
|
|||||||
};
|
};
|
||||||
|
|
||||||
# Wireguard VPNs
|
# Wireguard VPNs
|
||||||
systemd.services = cfg.wireguard-tunnels;
|
systemd.services = mkIf (!cfg.useNetworkManager) cfg.wireguard-tunnels;
|
||||||
|
|
||||||
# NOTE: I can connect to TU Dortmund directly
|
# NOTE: I can connect to TU Dortmund directly
|
||||||
# TODO: Use config with netns, like with wireguard
|
# TODO: Use config with netns, like with wireguard
|
||||||
@ -50,11 +59,11 @@ in {
|
|||||||
|
|
||||||
# TODO: Rewrite with lib.pipe
|
# TODO: Rewrite with lib.pipe
|
||||||
# Generate list of vpns for rofi menu
|
# Generate list of vpns for rofi menu
|
||||||
environment.etc."rofi-vpns".text = let
|
environment.etc."rofi-vpns" = let
|
||||||
names-list = attrNames cfg.wireguard-tunnels;
|
names-list = attrNames cfg.wireguard-tunnels;
|
||||||
names = concatStringsSep "\n" names-list;
|
names = concatStringsSep "\n" names-list;
|
||||||
in
|
in
|
||||||
names;
|
mkIf (!cfg.useNetworkManager) {text = names;};
|
||||||
|
|
||||||
# Allow to enable/disable tunnels without root password
|
# Allow to enable/disable tunnels without root password
|
||||||
modules.polkit.allowed-system-services = let
|
modules.polkit.allowed-system-services = let
|
||||||
@ -63,7 +72,7 @@ in {
|
|||||||
(map (v: "${v}.service"))
|
(map (v: "${v}.service"))
|
||||||
];
|
];
|
||||||
in
|
in
|
||||||
vpn-services;
|
mkIf (!cfg.useNetworkManager) vpn-services;
|
||||||
|
|
||||||
# General Networking Settings
|
# General Networking Settings
|
||||||
networking = {
|
networking = {
|
||||||
@ -73,7 +82,8 @@ in {
|
|||||||
|
|
||||||
# Disable a lot of stuff not needed for systemd-networkd
|
# Disable a lot of stuff not needed for systemd-networkd
|
||||||
networkmanager = {
|
networkmanager = {
|
||||||
enable = true;
|
enable = cfg.useNetworkManager;
|
||||||
|
ensureProfiles.profiles = cfg.profiles;
|
||||||
|
|
||||||
insertNameservers = [
|
insertNameservers = [
|
||||||
"192.168.86.26"
|
"192.168.86.26"
|
||||||
@ -89,10 +99,9 @@ in {
|
|||||||
useNetworkd = false; # Only use this if the configuration can't be written in systemd.network completely. It translates some of the networking... options to systemd
|
useNetworkd = false; # Only use this if the configuration can't be written in systemd.network completely. It translates some of the networking... options to systemd
|
||||||
# resolvconf.enable = true;
|
# resolvconf.enable = true;
|
||||||
|
|
||||||
# TODO
|
|
||||||
wireless = {
|
wireless = {
|
||||||
enable = false; # Enables wireless support via wpa_supplicant.
|
enable = false; # Enables wireless support via wpa_supplicant.
|
||||||
iwd.enable = false; # Use iwd instead of NetworkManager
|
iwd.enable = true; # Use iwd instead of wpa_supplicant
|
||||||
};
|
};
|
||||||
|
|
||||||
# Open Ports
|
# Open Ports
|
||||||
|
@ -7,6 +7,8 @@ with lib;
|
|||||||
with mylib.modules; {
|
with mylib.modules; {
|
||||||
enable = mkEnableOption "Systemd Network Configuration";
|
enable = mkEnableOption "Systemd Network Configuration";
|
||||||
|
|
||||||
|
useNetworkManager = mkEnableOption "Use NetworkManager instead of systemd-networkd";
|
||||||
|
|
||||||
hostname = mkOption {
|
hostname = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "The System's Hostname";
|
description = "The System's Hostname";
|
||||||
@ -28,6 +30,17 @@ with mylib.modules; {
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
profiles = mkOption {
|
||||||
|
type = types.attrs;
|
||||||
|
default = {};
|
||||||
|
description = "NetworkManager Profiles";
|
||||||
|
example = ''
|
||||||
|
"50-ether" = {
|
||||||
|
[...]
|
||||||
|
};
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
wireguard-tunnels = mkOption {
|
wireguard-tunnels = mkOption {
|
||||||
type = types.attrs;
|
type = types.attrs;
|
||||||
default = {};
|
default = {};
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
modules = {
|
modules = {
|
||||||
network = {
|
network = {
|
||||||
|
# Systemd-networkd configs
|
||||||
networks = {
|
networks = {
|
||||||
# This should override the default network 50-ether
|
# This should override the default network 50-ether
|
||||||
"10-ether-2_5G" = mylib.networking.mkStaticSystemdNetwork {
|
"10-ether-2_5G" = mylib.networking.mkStaticSystemdNetwork {
|
||||||
@ -31,6 +32,26 @@
|
|||||||
# "10-ether-1G" = mylib.networking.mkStaticSystemdNetwork {...};
|
# "10-ether-1G" = mylib.networking.mkStaticSystemdNetwork {...};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# NetworkManager profiles
|
||||||
|
profiles = {
|
||||||
|
"10-ether-2_5G" = mylib.networking.mkStaticNetworkManagerProfile {
|
||||||
|
id = "Wired 2.5G";
|
||||||
|
interface = "enp8s0";
|
||||||
|
ip = "192.168.86.50/24";
|
||||||
|
router = "192.168.86.5";
|
||||||
|
nameserver = "192.168.86.26";
|
||||||
|
autoconnect = true;
|
||||||
|
};
|
||||||
|
"10-ether-1G" = mylib.networking.mkStaticNetworkManagerProfile {
|
||||||
|
id = "Wired 1G";
|
||||||
|
interface = "enp5s0";
|
||||||
|
ip = "192.168.86.50/24";
|
||||||
|
router = "192.168.86.5";
|
||||||
|
nameserver = "192.168.86.26";
|
||||||
|
autoconnect = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
allowedTCPPorts = [
|
allowedTCPPorts = [
|
||||||
# 7777 # AvaTalk
|
# 7777 # AvaTalk
|
||||||
# 12777 # AvaTalk
|
# 12777 # AvaTalk
|
||||||
|
Reference in New Issue
Block a user