refactor: extract 'firewall' and 'wol' modules

This commit is contained in:
2026-02-23 23:40:15 +01:00
parent 34ebb265e6
commit e7c6df1c9b
4 changed files with 88 additions and 23 deletions

View File

@@ -24,23 +24,25 @@ in
inherit lib config; inherit lib config;
device = "/dev/nvme1n1"; device = "/dev/nvme1n1";
}) })
../../modules/desktops/niri ../../modules/audio
../../modules/backups ../../modules/backups
../../modules/bluetooth ../../modules/bluetooth
../../modules/gaming ../../modules/desktops/niri
../../modules/keyboard ../../modules/docker
(import ../../modules/networking { hostName = config.host.name; }) ../../modules/firewall
../../modules/users
../../modules/audio
../../modules/localization
../../modules/fonts ../../modules/fonts
../../modules/gaming
(import ../../modules/networking { hostName = config.host.name; })
../../modules/keyboard
../../modules/localization
../../modules/nvidia
(import ../../modules/secrets { inherit lib inputs config; })
../../modules/ssh ../../modules/ssh
../../modules/storage ../../modules/storage
../../modules/stylix ../../modules/stylix
(import ../../modules/secrets { inherit lib inputs config; })
../../modules/docker
../../modules/syncthing ../../modules/syncthing
../../modules/nvidia ../../modules/users
../../modules/wol
../../modules/yubikey ../../modules/yubikey
]; ];
@@ -113,17 +115,15 @@ in
package = pkgs.plocate; package = pkgs.plocate;
}; };
networking = { networking.hostId = "80eef97e";
# TODO: generate unique hostId on actual host with: head -c 8 /etc/machine-id
hostId = "80eef97e"; wol = {
interfaces = { enable = true;
eno1 = { interfaces.eno1 = { inherit (wolInterfaces.eno1) macAddress; };
wakeOnLan.enable = true; };
inherit (wolInterfaces.eno1) macAddress;
}; firewall = {
}; enable = true;
firewall = { allowedTCPPorts = [ 22 ];
allowedUDPPorts = [ 9 ];
};
}; };
} }

View File

@@ -38,6 +38,7 @@ in
(import ../../modules/secrets { inherit lib inputs config; }) (import ../../modules/secrets { inherit lib inputs config; })
../../modules/docker ../../modules/docker
../../modules/nfc ../../modules/nfc
../../modules/firewall
]; ];
home-manager.users.${config.host.username} = import ../../home/hosts/astyanax { home-manager.users.${config.host.username} = import ../../home/hosts/astyanax {
@@ -89,10 +90,14 @@ in
]; ];
networking = { networking = {
# TODO: generate unique hostId on actual host with: head -c 8 /etc/machine-id
hostId = "80eef97e"; hostId = "80eef97e";
}; };
firewall = {
enable = true;
allowedTCPPorts = [ 22 ];
};
boot.binfmt.emulatedSystems = [ "aarch64-linux" ]; boot.binfmt.emulatedSystems = [ "aarch64-linux" ];
services = { services = {

View File

@@ -0,0 +1,27 @@
{ lib, config, ... }:
let
inherit (lib) mkEnableOption mkOption types;
in
{
options.firewall = {
enable = mkEnableOption "firewall";
allowedTCPPorts = mkOption {
type = types.listOf types.port;
default = [ ];
};
allowedUDPPorts = mkOption {
type = types.listOf types.port;
default = [ ];
};
};
config = lib.mkIf config.firewall.enable {
networking.firewall = {
enable = true;
inherit (config.firewall) allowedTCPPorts allowedUDPPorts;
};
};
}

33
modules/wol/default.nix Normal file
View File

@@ -0,0 +1,33 @@
{ lib, config, ... }:
let
inherit (lib) mkEnableOption mkOption types;
in
{
options.wol = {
enable = mkEnableOption "Wake-on-LAN configuration";
interfaces = mkOption {
type = types.attrsOf (
types.submodule {
options = {
macAddress = mkOption {
type = types.str;
example = "02:68:b3:29:da:98";
};
};
}
);
default = { };
};
};
config = lib.mkIf config.wol.enable {
networking.interfaces = lib.mapAttrs (_: iface: {
wakeOnLan.enable = true;
inherit (iface) macAddress;
}) config.wol.interfaces;
# firewall.allowedUDPPorts = [ 9 ];
};
}