static net

This commit is contained in:
2025-04-08 21:25:08 -04:00
parent a1a5ee1f8f
commit 4026a01425
2 changed files with 52 additions and 33 deletions

View File

@@ -1,6 +1,6 @@
{ config, lib, pkgs, namespace, ... }:
let
inherit (lib) mkIf mkDefault mkEnableOption;
inherit (lib) types mkIf mkDefault mkOption mkEnableOption;
inherit (lib.${namespace}) mkBoolOpt enabled;
cfg = config.${namespace}.system.networking;
@@ -11,6 +11,35 @@ in
enableIWD = mkEnableOption "Enable IWD";
useDHCP = mkBoolOpt true "Use DHCP";
useNetworkd = mkBoolOpt false "Use networkd";
useStatic = mkOption {
type = types.nullOr (types.submodule {
options = {
interface = mkOption {
type = lib.types.str;
description = "Network interface name";
example = "enp0s3";
};
address = mkOption {
type = types.str;
description = "Static IP address";
example = "10.0.20.200";
};
defaultGateway = mkOption {
type = types.str;
description = "Default gateway IP";
example = "10.0.20.254";
};
nameservers = mkOption {
type = types.listOf types.str;
description = "List of DNS servers";
example = [ "10.0.20.254" "8.8.8.8" ];
default = [ "8.8.8.8" "8.8.4.4" ];
};
};
});
default = null;
description = "Static Network Configuration";
};
};
config = mkIf cfg.enable {
@@ -24,24 +53,19 @@ in
networking = {
firewall = enabled;
useDHCP = mkDefault cfg.useDHCP;
useDHCP = mkIf (cfg.useStatic == null) (mkDefault cfg.useDHCP);
useNetworkd = cfg.useNetworkd;
} // (lib.optionalAttrs cfg.enableIWD) {
} // (lib.optionalAttrs (cfg.enableIWD) {
wireless.iwd = {
enable = true;
settings.General.EnableNetworkConfiguration = true;
};
};
# TODO - Network Configuration
# (lib.mkIf (config.network != null) {
# networking = {
# inherit (config.network) defaultGateway nameservers;
# interfaces.${config.network.interface}.ipv4.addresses = [{
# inherit (config.network) address;
# prefixLength = 24;
# }];
# };
# })
}) // (lib.optionalAttrs (cfg.useStatic != null) {
inherit (cfg.useStatic) defaultGateway nameservers;
interfaces.${cfg.useStatic.interface}.ipv4.addresses = [{
inherit (cfg.useStatic) address;
prefixLength = 24;
}];
});
};
}