This commit is contained in:
Kopatz
2025-02-18 23:59:13 +01:00
parent 32e8a7af77
commit 3b0c8bcfcc
2 changed files with 45 additions and 48 deletions

View File

@@ -1,46 +1,48 @@
{config, lib, ...}:
{ config, lib, ... }:
with lib;
let
cfg = config.custom.static-ip;
in
{
options.custom.static-ip = {
enable = mkEnableOption "Enables static-ip";
ip = lib.mkOption {
type = types.str;
description = "ipv4 address";
let cfg = config.custom.static-ip;
in {
options.custom.static-ip = {
enable = mkEnableOption "Enables static-ip";
ip = lib.mkOption {
type = types.str;
description = "ipv4 address";
};
dns = lib.mkOption {
type = types.str;
description = "ip of the dns server";
};
interface = lib.mkOption {
type = types.str;
description = "interface to apply the change to";
};
gateway = lib.mkOption {
type = types.str;
default = "192.168.0.1";
description = "Default gateway";
};
};
config = let fallback = "1.1.1.1";
in mkIf cfg.enable {
networking = {
defaultGateway = cfg.gateway;
useDHCP = false;
nameservers = [ cfg.dns ]
++ lib.lists.optionals (!config.services.resolved.enable) [ fallback ];
interfaces = {
${cfg.interface} = {
name = "eth0";
ipv4.addresses = [{
address = cfg.ip;
prefixLength = 24;
}];
};
};
dns = lib.mkOption {
type = types.str;
description = "ip of the dns server";
};
interface = lib.mkOption {
type = types.str;
description = "interface to apply the change to";
};
gateway = lib.mkOption {
type = types.str;
default = "192.168.0.1";
description = "Default gateway";
};
};
config = mkIf cfg.enable {
networking = {
defaultGateway = cfg.gateway;
useDHCP = false;
nameservers = [
cfg.dns
"1.1.1.1"
];
interfaces = {
${cfg.interface} = {
name = "eth0";
ipv4.addresses = [{
address = cfg.ip;
prefixLength = 24;
}];
};
};
};
};
services.resolved = lib.mkIf config.services.resolved.enable {
llmnr = "false";
fallbackDns = [ "1.1.1.1" ];
};
};
}