feat: network homelab module
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
../../modules/nixos/config/host.nix
|
||||
../../modules/nixos/homelab
|
||||
./hardware-configuration.nix
|
||||
./network.nix
|
||||
./secrets.nix
|
||||
./users
|
||||
];
|
||||
@@ -18,11 +17,18 @@
|
||||
homelab = {
|
||||
enable = true;
|
||||
flakeDir = "/home/guz/.nix#homex";
|
||||
name = "homex";
|
||||
|
||||
domain = "guz.local";
|
||||
|
||||
ip = "100.66.139.89";
|
||||
localIp = "192.168.1.10";
|
||||
|
||||
network = {
|
||||
enable = true;
|
||||
interface = "eno1";
|
||||
};
|
||||
|
||||
tailscale = {
|
||||
enable = true;
|
||||
mode = "both";
|
||||
|
||||
@@ -4,20 +4,6 @@
|
||||
imports = [ ];
|
||||
config = {
|
||||
host.networking.hostName = "homex";
|
||||
networking = {
|
||||
dhcpcd.enable = true;
|
||||
interfaces.eno1.ipv4.addresses = [{
|
||||
address = "192.168.1.10";
|
||||
prefixLength = 28;
|
||||
}];
|
||||
defaultGateway = "192.168.1.1";
|
||||
nameservers = [ "100.100.100.100" "1.1.1.1" "8.8.8.8" ];
|
||||
};
|
||||
|
||||
boot.kernel.sysctl."net.ipv4.ip_forward" = 1;
|
||||
boot.kernel.sysctl."net.ipv6.conf.all.forwarding" = 1;
|
||||
|
||||
services.openssh.enable = true;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ in
|
||||
./adguard.nix
|
||||
./caddy.nix
|
||||
./forgejo.nix
|
||||
./network.nix
|
||||
./tailscale.nix
|
||||
];
|
||||
options.homelab = with lib; with lib.types; {
|
||||
@@ -42,12 +43,13 @@ in
|
||||
type = either str path;
|
||||
default = "homelab.local";
|
||||
};
|
||||
ip = mkOption {
|
||||
type = str;
|
||||
};
|
||||
localIp = mkOption {
|
||||
type = str;
|
||||
};
|
||||
ip = mkOption {
|
||||
type = str;
|
||||
default = cfg.localIp;
|
||||
};
|
||||
handleDomains = mkOption {
|
||||
type = bool;
|
||||
default = true;
|
||||
|
||||
56
modules/nixos/homelab/network.nix
Normal file
56
modules/nixos/homelab/network.nix
Normal file
@@ -0,0 +1,56 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
cfg = config.homelab.network;
|
||||
in
|
||||
{
|
||||
imports = [ ];
|
||||
options.homelab.network = with lib; with lib.types; {
|
||||
enable = mkOption {
|
||||
type = bool;
|
||||
default = true;
|
||||
};
|
||||
interface = mkOption {
|
||||
type = str;
|
||||
};
|
||||
localIp = mkOption {
|
||||
type = str;
|
||||
default = config.homelab.localIp;
|
||||
};
|
||||
defaultGateway = mkOption {
|
||||
type = str;
|
||||
default = "192.168.1.1";
|
||||
};
|
||||
nameservers = mkOption {
|
||||
type = listOf str;
|
||||
default = [ "1.1.1.1" "8.8.8.8" ];
|
||||
};
|
||||
portForwarding = mkOption {
|
||||
type = bool;
|
||||
default = false;
|
||||
};
|
||||
openssh = mkOption {
|
||||
type = bool;
|
||||
default = true;
|
||||
};
|
||||
settings = { };
|
||||
};
|
||||
config = lib.mkIf cfg.enable {
|
||||
networking = {
|
||||
dhcpcd.enable = true;
|
||||
interfaces."${cfg.interface}".ipv4.addresses = [{
|
||||
address = cfg.localIp;
|
||||
prefixLength = 28;
|
||||
}];
|
||||
defaultGateway = cfg.defaultGateway;
|
||||
nameservers = [
|
||||
(if config.homelab.tailscale.enable then "100.100.100.100" else null)
|
||||
] ++ cfg.nameservers;
|
||||
};
|
||||
|
||||
boot.kernel.sysctl."net.ipv4.ip_forward" = if cfg.portForwarding then 1 else 0;
|
||||
boot.kernel.sysctl."net.ipv6.conf.all.forwarding" = if cfg.portForwarding then 1 else 0;
|
||||
|
||||
services.openssh.enable = cfg.openssh;
|
||||
};
|
||||
}
|
||||
@@ -28,6 +28,9 @@ in
|
||||
enable = true;
|
||||
useRoutingFeatures = cfg.mode;
|
||||
};
|
||||
|
||||
homelab.network = lib.mkIf cfg.exitNode { portForwarding = lib.mkDefault true; };
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user