Files
nix-config/system/network/networking.nix

79 lines
1.9 KiB
Nix
Raw Normal View History

2025-05-04 02:47:36 +02:00
{
lib,
config,
...
}:
with lib; let
2025-08-15 21:33:22 +02:00
cfg = config.mySystem.networking;
2025-05-04 02:47:36 +02:00
in {
2025-08-15 21:33:22 +02:00
options.mySystem.networking = with types; {
2025-05-04 02:47:36 +02:00
hostname = mkOption {
type = str;
2025-05-04 02:47:36 +02:00
example = "gampo";
};
id = mkOption {
type = str;
2025-05-04 02:47:36 +02:00
example = "deadb33f";
};
domain = mkOption {
type = nullOr str;
example = "phundrak.com";
default = null;
};
2025-05-04 02:47:36 +02:00
hostFiles = mkOption {
type = listOf path;
2025-05-04 02:47:36 +02:00
example = [/path/to/hostFile];
default = [];
};
firewall = {
openPorts = mkOption {
type = listOf int;
2025-05-04 02:47:36 +02:00
example = [22 80 443];
default = [];
};
openPortRanges = mkOption {
type = listOf (attrsOf port);
2025-05-04 02:47:36 +02:00
default = [];
example = [
{
from = 8080;
to = 8082;
}
];
description = ''
A range of TCP and UDP ports on which incoming connections are
accepted.
'';
};
extraCommands = mkOption {
type = nullOr lines;
2025-05-04 02:47:36 +02:00
example = "iptables -A INPUTS -p icmp -j ACCEPT";
default = null;
};
};
2026-03-26 22:30:44 +01:00
wifi.disablePowersave = mkEnableOption ''
Disables powersave for Wifi.
Used mainly for the PineTab2, as leaving WiFi powersave with the bes2600 can cause stability issues.
'';
2025-05-04 02:47:36 +02:00
};
config.networking = {
hostName = cfg.hostname; # Define your hostname.
hostId = cfg.id;
2026-03-26 22:30:44 +01:00
networkmanager = {
enable = true;
wifi.powersave = ! cfg.wifi.disablePowersave;
};
inherit (cfg) hostFiles domain;
2025-05-04 02:47:36 +02:00
firewall = {
enable = true;
allowedTCPPorts = cfg.firewall.openPorts;
allowedUDPPorts = cfg.firewall.openPorts;
allowedTCPPortRanges = cfg.firewall.openPortRanges;
allowedUDPPortRanges = cfg.firewall.openPortRanges;
extraCommands = (mkIf (cfg.firewall.extraCommands != null)) cfg.firewall.extraCommands;
};
};
}