System: Rename systemd-networkd module to network
This commit is contained in:
117
system/modules/network/default.nix
Normal file
117
system/modules/network/default.nix
Normal file
@ -0,0 +1,117 @@
|
||||
# TODO: Setup Wireless (IWD/Networkd?)
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
mylib,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
with mylib.networking;
|
||||
with mylib.modules; let
|
||||
cfg = config.modules.network;
|
||||
in {
|
||||
options.modules.network = import ./options.nix {inherit lib mylib;};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.resolved.enable = true;
|
||||
services.resolved.llmnr = "false";
|
||||
|
||||
# Main Networks
|
||||
systemd.network = {
|
||||
enable = true;
|
||||
wait-online.timeout = 10;
|
||||
|
||||
# Don't wait for all networks to be configured, as e.g. wg0 will only be upon manual activation
|
||||
wait-online.anyInterface = true;
|
||||
|
||||
# TODO: Apparently anyInterface doesn't work?
|
||||
# wait-online.ignoredInterfaces = [
|
||||
# "wg0"
|
||||
# "wlp7s0"
|
||||
# "enp5s0"
|
||||
# ];
|
||||
|
||||
# networks = cfg.networks;
|
||||
inherit (cfg) networks;
|
||||
};
|
||||
|
||||
# Wireguard VPNs
|
||||
systemd.services = cfg.wireguard-tunnels;
|
||||
|
||||
# NOTE: I can connect to TU Dortmund directly
|
||||
# TODO: Use config with netns, like with wireguard
|
||||
# services.openvpn.servers = {
|
||||
# # TODO: Can't read config file...
|
||||
# tu-dortmund-irb = {
|
||||
# autoStart = false;
|
||||
# config = "config ~/NixFlake/config/openvpn/tu-dortmund-irb.ovpn";
|
||||
# };
|
||||
# };
|
||||
|
||||
# TODO: Rewrite with lib.pipe
|
||||
# Generate list of vpns for rofi menu
|
||||
environment.etc."rofi-vpns".text = let
|
||||
names-list = attrNames cfg.wireguard-tunnels;
|
||||
names = concatStringsSep "\n" names-list;
|
||||
in
|
||||
names;
|
||||
|
||||
# Allow to enable/disable tunnels without root password
|
||||
modules.polkit.allowed-system-services = let
|
||||
vpn-services = lib.pipe cfg.wireguard-tunnels [
|
||||
attrNames
|
||||
(map (v: "${v}.service"))
|
||||
];
|
||||
in
|
||||
vpn-services;
|
||||
|
||||
# General Networking Settings
|
||||
networking = {
|
||||
# Gets inherited from flake in nixos mylib and passed through the module option
|
||||
hostName = cfg.hostname; # Define your hostname.
|
||||
enableIPv6 = false;
|
||||
|
||||
# Disable a lot of stuff not needed for systemd-networkd
|
||||
networkmanager = {
|
||||
enable = true;
|
||||
|
||||
insertNameservers = [
|
||||
"192.168.86.26"
|
||||
];
|
||||
|
||||
wifi = {
|
||||
backend = "iwd";
|
||||
};
|
||||
};
|
||||
|
||||
useDHCP = false; # Default: true, don't use with networkd
|
||||
dhcpcd.enable = false; # Don't use with networkd
|
||||
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;
|
||||
|
||||
# TODO
|
||||
wireless = {
|
||||
enable = false; # Enables wireless support via wpa_supplicant.
|
||||
iwd.enable = false; # Use iwd instead of NetworkManager
|
||||
};
|
||||
|
||||
# Open Ports
|
||||
nftables.enable = true;
|
||||
firewall = {
|
||||
enable = true;
|
||||
# networking.firewall.checkReversePath = "loose";
|
||||
|
||||
trustedInterfaces = [
|
||||
"podman0"
|
||||
"docker0"
|
||||
];
|
||||
|
||||
# allowedTCPPorts = cfg.allowedTCPPorts;
|
||||
# allowedTCPPortRanges = [];
|
||||
# allowedUDPPorts = cfg.allowedUDPPorts;
|
||||
# allowedUDPPortRanges = [];
|
||||
inherit (cfg) allowerdTCPPorts allowerdUDPPorts;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
59
system/modules/network/options.nix
Normal file
59
system/modules/network/options.nix
Normal file
@ -0,0 +1,59 @@
|
||||
{
|
||||
lib,
|
||||
mylib,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
with mylib.modules; {
|
||||
enable = mkEnableOption "Systemd Network Configuration";
|
||||
|
||||
hostname = mkOption {
|
||||
type = types.str;
|
||||
description = "The System's Hostname";
|
||||
example = ''
|
||||
"Nixinator"
|
||||
'';
|
||||
};
|
||||
|
||||
networks = mkOption {
|
||||
type = types.attrs;
|
||||
default = {};
|
||||
description = "Systemd-Networkd Networks";
|
||||
example = ''
|
||||
{
|
||||
"50-ether" = {
|
||||
[...]
|
||||
};
|
||||
}
|
||||
'';
|
||||
};
|
||||
|
||||
wireguard-tunnels = mkOption {
|
||||
type = types.attrs;
|
||||
default = {};
|
||||
description = "Wireguard VPN Tunnels";
|
||||
example = ''
|
||||
wg0-de-115 = {
|
||||
[...]
|
||||
};
|
||||
'';
|
||||
};
|
||||
|
||||
allowedTCPPorts = mkOption {
|
||||
type = types.listOf types.int;
|
||||
default = [];
|
||||
description = "Open TCP Ports in the Firewall";
|
||||
example = ''
|
||||
[22 80 443]
|
||||
'';
|
||||
};
|
||||
|
||||
allowedUDPPorts = mkOption {
|
||||
type = types.listOf types.int;
|
||||
default = [];
|
||||
description = "Open UDP Ports in the Firewall";
|
||||
example = ''
|
||||
[22 80 443]
|
||||
'';
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user