router: move most configuration into modules with options
This commit is contained in:
parent
a3f351cf38
commit
47c9cff8f5
@ -1,91 +1,19 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
|
||||||
let
|
|
||||||
vars = import ./vars.nix;
|
|
||||||
enableDesktop = false;
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
imports =
|
imports = [
|
||||||
[ # Include the results of the hardware scan.
|
../../modules/router
|
||||||
./hardware-configuration.nix
|
./hardware-configuration.nix
|
||||||
./ifconfig.nix
|
./private.nix
|
||||||
./wireguard.nix
|
|
||||||
./firewall.nix
|
|
||||||
./dns.nix
|
|
||||||
./kea.nix
|
|
||||||
./glance.nix
|
|
||||||
./services.nix
|
|
||||||
];
|
|
||||||
# Secrix for secrets management
|
|
||||||
secrix.hostPubKey = vars.pubkey;
|
|
||||||
|
|
||||||
# Bootloader.
|
|
||||||
boot.loader.systemd-boot.enable = true;
|
|
||||||
boot.loader.efi.canTouchEfiVariables = false;
|
|
||||||
boot.kernelParams = [
|
|
||||||
"sysrq_always_enabled=1"
|
|
||||||
];
|
];
|
||||||
|
|
||||||
boot.loader.timeout = 2;
|
router = {
|
||||||
boot.loader.systemd-boot.configurationLimit = 5;
|
enableDesktop = false;
|
||||||
boot.kernelPackages = pkgs.linuxKernel.packages.linux_6_12;
|
enableDhcpClient = true;
|
||||||
boot.growPartition = true;
|
wanMAC = "bc:24:11:4f:c9:c4";
|
||||||
|
lanMAC = "bc:24:11:83:d8:de";
|
||||||
|
wanLL = "fe80::be24:11ff:fe4f:c9c4";
|
||||||
|
lanLL = "fe80::be24:11ff:fe83:d8de";
|
||||||
|
defaultToken = 1;
|
||||||
|
};
|
||||||
|
|
||||||
networking.hostName = "grouter";
|
networking.hostName = "grouter";
|
||||||
|
|
||||||
# Enable the X11 windowing system.
|
|
||||||
# You can disable this if you're only using the Wayland session.
|
|
||||||
services.xserver.enable = false;
|
|
||||||
|
|
||||||
# Enable the KDE Plasma Desktop Environment.
|
|
||||||
# Useful for debugging with wireshark.
|
|
||||||
hardware.graphics.enable = true;
|
|
||||||
services.displayManager.sddm.enable = enableDesktop;
|
|
||||||
services.displayManager.sddm.wayland.enable = enableDesktop;
|
|
||||||
services.desktopManager.plasma6.enable = enableDesktop;
|
|
||||||
# No need for audio in VM
|
|
||||||
services.pipewire.enable = false;
|
|
||||||
|
|
||||||
# VM services
|
|
||||||
services.qemuGuest.enable = true;
|
|
||||||
services.spice-vdagentd.enable = true;
|
|
||||||
|
|
||||||
security.sudo.wheelNeedsPassword = false;
|
|
||||||
|
|
||||||
programs.firefox.enable = true;
|
|
||||||
programs.fish.enable = true;
|
|
||||||
programs.git.enable = true;
|
|
||||||
programs.neovim.enable = true;
|
|
||||||
programs.bat.enable = true;
|
|
||||||
programs.htop.enable = true;
|
|
||||||
programs.wireshark.enable = true;
|
|
||||||
programs.wireshark.package = pkgs.wireshark; # wireshark-cli by default
|
|
||||||
|
|
||||||
environment.systemPackages = with pkgs; [
|
|
||||||
dust
|
|
||||||
eza
|
|
||||||
fastfetch
|
|
||||||
fd
|
|
||||||
kdePackages.kate
|
|
||||||
ldns
|
|
||||||
lsof
|
|
||||||
micro
|
|
||||||
mpv
|
|
||||||
openssl
|
|
||||||
ripgrep
|
|
||||||
rustscan
|
|
||||||
starship
|
|
||||||
tealdeer
|
|
||||||
transcrypt
|
|
||||||
waypipe
|
|
||||||
whois
|
|
||||||
wireguard-tools
|
|
||||||
];
|
|
||||||
|
|
||||||
# This value determines the NixOS release from which the default
|
|
||||||
# settings for stateful data, like file locations and database versions
|
|
||||||
# on your system were taken. It‘s perfectly fine and recommended to leave
|
|
||||||
# this value at the release version of the first install of this system.
|
|
||||||
# Before changing this value read the documentation for this option
|
|
||||||
# (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
|
|
||||||
system.stateVersion = "24.11"; # Did you read the comment?
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
U2FsdGVkX1/MGwxIMmhbZuPqJUZzex9v5tTuiOrEvDVldI7xY0edUy9Ii5udFLXt
|
U2FsdGVkX1+eMFkQxarJDGLkX0zXyMRPukeRNvzd/BJ0XDAUZ2EeZvQnZw8U53Xz
|
||||||
AbxShsH43FH1ucgygKDlKTB/yXZWDoDVhjdgLFjaBtAt0xyAL9Doet844oDVhbbO
|
W97X4rvT+K/NQ7FVCYfOg1XpQhzlSiC9z1M4WLmPRutUgsDY5n5RFJu2R8K5DAfi
|
||||||
FqOwXHMd+PE23rgqiCscsA==
|
sAPcxiQUGVKrmDUva16yNqoR2Dkx2XE9iW1hpkfGFYVUK+QKIBkUEowQQlJJ1Wg1
|
||||||
|
91
modules/router/default.nix
Normal file
91
modules/router/default.nix
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
let
|
||||||
|
vars = import ./vars.nix config;
|
||||||
|
enableDesktop = config.router.enableDesktop;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
imports =
|
||||||
|
[ # Include the results of the hardware scan.
|
||||||
|
./opts.nix
|
||||||
|
./ifconfig.nix
|
||||||
|
./wireguard.nix
|
||||||
|
./firewall.nix
|
||||||
|
./dns.nix
|
||||||
|
./kea.nix
|
||||||
|
./glance.nix
|
||||||
|
./services.nix
|
||||||
|
];
|
||||||
|
# Secrix for secrets management
|
||||||
|
secrix.hostPubKey = vars.pubkey;
|
||||||
|
|
||||||
|
# Bootloader.
|
||||||
|
boot.loader.systemd-boot.enable = true;
|
||||||
|
boot.loader.efi.canTouchEfiVariables = false;
|
||||||
|
boot.kernelParams = [
|
||||||
|
"sysrq_always_enabled=1"
|
||||||
|
];
|
||||||
|
|
||||||
|
boot.loader.timeout = 2;
|
||||||
|
boot.loader.systemd-boot.configurationLimit = 5;
|
||||||
|
boot.kernelPackages = pkgs.linuxKernel.packages.linux_6_12;
|
||||||
|
boot.growPartition = true;
|
||||||
|
|
||||||
|
# Enable the X11 windowing system.
|
||||||
|
# You can disable this if you're only using the Wayland session.
|
||||||
|
services.xserver.enable = false;
|
||||||
|
|
||||||
|
# Enable the KDE Plasma Desktop Environment.
|
||||||
|
# Useful for debugging with wireshark.
|
||||||
|
hardware.graphics.enable = true;
|
||||||
|
services.xserver.desktopManager.xfce.enable = enableDesktop;
|
||||||
|
services.xserver.desktopManager.xfce.enableWaylandSession = enableDesktop;
|
||||||
|
# services.displayManager.sddm.enable = enableDesktop;
|
||||||
|
# services.displayManager.sddm.wayland.enable = enableDesktop;
|
||||||
|
# services.desktopManager.plasma6.enable = enableDesktop;
|
||||||
|
# No need for audio in VM
|
||||||
|
services.pipewire.enable = false;
|
||||||
|
|
||||||
|
# VM services
|
||||||
|
services.qemuGuest.enable = true;
|
||||||
|
services.spice-vdagentd.enable = true;
|
||||||
|
|
||||||
|
security.sudo.wheelNeedsPassword = false;
|
||||||
|
|
||||||
|
programs.firefox.enable = true;
|
||||||
|
programs.fish.enable = true;
|
||||||
|
programs.git.enable = true;
|
||||||
|
programs.neovim.enable = true;
|
||||||
|
programs.bat.enable = true;
|
||||||
|
programs.htop.enable = true;
|
||||||
|
programs.wireshark.enable = true;
|
||||||
|
programs.wireshark.package = pkgs.wireshark; # wireshark-cli by default
|
||||||
|
|
||||||
|
environment.systemPackages = with pkgs; [
|
||||||
|
dust
|
||||||
|
eza
|
||||||
|
fastfetch
|
||||||
|
fd
|
||||||
|
kdePackages.kate
|
||||||
|
ldns
|
||||||
|
lsof
|
||||||
|
micro
|
||||||
|
mpv
|
||||||
|
openssl
|
||||||
|
ripgrep
|
||||||
|
rustscan
|
||||||
|
starship
|
||||||
|
tealdeer
|
||||||
|
transcrypt
|
||||||
|
waypipe
|
||||||
|
whois
|
||||||
|
wireguard-tools
|
||||||
|
];
|
||||||
|
|
||||||
|
# This value determines the NixOS release from which the default
|
||||||
|
# settings for stateful data, like file locations and database versions
|
||||||
|
# on your system were taken. It‘s perfectly fine and recommended to leave
|
||||||
|
# this value at the release version of the first install of this system.
|
||||||
|
# Before changing this value read the documentation for this option
|
||||||
|
# (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
|
||||||
|
system.stateVersion = "24.11"; # Did you read the comment?
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
let
|
let
|
||||||
vars = import ./vars.nix;
|
vars = import ./vars.nix config;
|
||||||
domain = vars.domain;
|
domain = vars.domain;
|
||||||
ldomain = vars.ldomain;
|
ldomain = vars.ldomain;
|
||||||
sysdomain = vars.sysdomain;
|
sysdomain = vars.sysdomain;
|
@ -1,6 +1,6 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
let
|
let
|
||||||
vars = import ./vars.nix;
|
vars = import ./vars.nix config;
|
||||||
links = vars.links;
|
links = vars.links;
|
||||||
ifs = vars.ifs;
|
ifs = vars.ifs;
|
||||||
pdFromWan = vars.pdFromWan;
|
pdFromWan = vars.pdFromWan;
|
@ -1,6 +1,6 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
let
|
let
|
||||||
vars = import ./vars.nix;
|
vars = import ./vars.nix config;
|
||||||
domain = vars.domain;
|
domain = vars.domain;
|
||||||
in
|
in
|
||||||
{
|
{
|
@ -1,6 +1,7 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
let
|
let
|
||||||
vars = import ./vars.nix;
|
cfg = config.router;
|
||||||
|
vars = import ./vars.nix config;
|
||||||
links = vars.links;
|
links = vars.links;
|
||||||
ifs = vars.ifs;
|
ifs = vars.ifs;
|
||||||
pdFromWan = vars.pdFromWan;
|
pdFromWan = vars.pdFromWan;
|
||||||
@ -57,7 +58,7 @@ in
|
|||||||
# https://github.com/systemd/systemd/issues/22571
|
# https://github.com/systemd/systemd/issues/22571
|
||||||
# https://github.com/systemd/systemd/issues/22571#issuecomment-2094905496
|
# https://github.com/systemd/systemd/issues/22571#issuecomment-2094905496
|
||||||
# https://gist.github.com/csamsel/0f8cca3b2e64d7e4cc47819ec5ba9396
|
# https://gist.github.com/csamsel/0f8cca3b2e64d7e4cc47819ec5ba9396
|
||||||
networking.dhcpcd.enable = true;
|
networking.dhcpcd.enable = cfg.enableDhcpClient;
|
||||||
networking.dhcpcd.allowInterfaces = [ ifs.wan.name ];
|
networking.dhcpcd.allowInterfaces = [ ifs.wan.name ];
|
||||||
networking.dhcpcd.extraConfig = ''
|
networking.dhcpcd.extraConfig = ''
|
||||||
debug
|
debug
|
@ -1,6 +1,6 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
let
|
let
|
||||||
vars = import ./vars.nix;
|
vars = import ./vars.nix config;
|
||||||
ldomain = vars.ldomain;
|
ldomain = vars.ldomain;
|
||||||
ifs = vars.ifs;
|
ifs = vars.ifs;
|
||||||
|
|
69
modules/router/opts.nix
Normal file
69
modules/router/opts.nix
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
{ lib, config, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
router = {
|
||||||
|
enableDesktop = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = "Enable desktop environment for debugging";
|
||||||
|
};
|
||||||
|
|
||||||
|
enableDhcpClient = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = "Enable DHCP client (should only be set on the main router)";
|
||||||
|
};
|
||||||
|
|
||||||
|
wanMAC = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "bc:24:11:4f:c9:c4";
|
||||||
|
description = "WAN interface MAC address";
|
||||||
|
};
|
||||||
|
|
||||||
|
lanMAC = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "bc:24:11:83:d8:de";
|
||||||
|
description = "LAN interface MAC address";
|
||||||
|
};
|
||||||
|
|
||||||
|
wanLL = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "fe80::be24:11ff:fe4f:c9c4";
|
||||||
|
description = "WAN IPv6 link-local address";
|
||||||
|
};
|
||||||
|
|
||||||
|
lanLL = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "fe80::be24:11ff:fe83:d8de";
|
||||||
|
description = "LAN IPv6 link-local address";
|
||||||
|
};
|
||||||
|
|
||||||
|
defaultToken = mkOption {
|
||||||
|
type = types.int;
|
||||||
|
default = 1;
|
||||||
|
description = "Default token for interface addressing";
|
||||||
|
};
|
||||||
|
|
||||||
|
wanAddr4 = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "192.168.1.61";
|
||||||
|
description = "WAN IPv4 address";
|
||||||
|
};
|
||||||
|
|
||||||
|
wanGw4 = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "192.168.1.254";
|
||||||
|
description = "WAN IPv4 gateway";
|
||||||
|
};
|
||||||
|
|
||||||
|
pdFromWan = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "2001:db8:0:000";
|
||||||
|
description = "IPv6 prefix delegation from ISP (/60)";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
let
|
let
|
||||||
vars = import ./vars.nix;
|
vars = import ./vars.nix config;
|
||||||
domain = vars.domain;
|
domain = vars.domain;
|
||||||
in
|
in
|
||||||
{
|
{
|
@ -1,6 +1,6 @@
|
|||||||
|
config:
|
||||||
let
|
let
|
||||||
private = import ./private.nix;
|
cfg = config.router;
|
||||||
|
|
||||||
mkIfConfig = {
|
mkIfConfig = {
|
||||||
name_,
|
name_,
|
||||||
domain_,
|
domain_,
|
||||||
@ -10,7 +10,7 @@ let
|
|||||||
p6Size_ ? 64,
|
p6Size_ ? 64,
|
||||||
ulaPrefix_, # /64
|
ulaPrefix_, # /64
|
||||||
ulaSize_ ? 64,
|
ulaSize_ ? 64,
|
||||||
token? 1,
|
token? cfg.defaultToken,
|
||||||
ip6Token_? "::${toString token}",
|
ip6Token_? "::${toString token}",
|
||||||
ulaToken_? "::${toString token}",
|
ulaToken_? "::${toString token}",
|
||||||
}: rec {
|
}: rec {
|
||||||
@ -41,21 +41,21 @@ rec {
|
|||||||
ldomain = "l.${domain}";
|
ldomain = "l.${domain}";
|
||||||
sysdomain = "sys.${domain}";
|
sysdomain = "sys.${domain}";
|
||||||
links = {
|
links = {
|
||||||
wanMAC = "bc:24:11:4f:c9:c4";
|
wanMAC = cfg.wanMAC;
|
||||||
lanMAC = "bc:24:11:83:d8:de";
|
lanMAC = cfg.lanMAC;
|
||||||
wanLL = "fe80::be24:11ff:fe4f:c9c4";
|
wanLL = cfg.wanLL;
|
||||||
lanLL = "fe80::be24:11ff:fe83:d8de";
|
lanLL = cfg.lanLL;
|
||||||
};
|
};
|
||||||
|
|
||||||
p4 = "10.17"; # .0.0/16
|
p4 = "10.17"; # .0.0/16
|
||||||
pdFromWan = private.pdFromWan; # ::/60
|
pdFromWan = cfg.pdFromWan; # ::/60
|
||||||
ulaPrefix = "fdab:07d3:581d"; # ::/48
|
ulaPrefix = "fdab:07d3:581d"; # ::/48
|
||||||
ifs = rec {
|
ifs = rec {
|
||||||
wan = rec {
|
wan = rec {
|
||||||
name = "wan";
|
name = "wan";
|
||||||
addr4 = private.wanAddr4;
|
addr4 = cfg.wanAddr4;
|
||||||
addr4Sized = "${addr4}/23";
|
addr4Sized = "${addr4}/24";
|
||||||
gw4 = private.wanGw4;
|
gw4 = cfg.wanGw4;
|
||||||
};
|
};
|
||||||
lan = mkIfConfig {
|
lan = mkIfConfig {
|
||||||
name_ = "lan";
|
name_ = "lan";
|
||||||
@ -77,7 +77,7 @@ rec {
|
|||||||
p4_ = "${p4}.20"; # .0/24
|
p4_ = "${p4}.20"; # .0/24
|
||||||
p6_ = "${pdFromWan}0"; # ::/64 managed by Att box
|
p6_ = "${pdFromWan}0"; # ::/64 managed by Att box
|
||||||
ulaPrefix_ = "${ulaPrefix}:0020"; # ::/64
|
ulaPrefix_ = "${ulaPrefix}:0020"; # ::/64
|
||||||
ip6Token_ = "::1:1"; # override ipv6 for lan20, since the Att box uses ::1 here
|
ip6Token_ = "::1:${toString cfg.defaultToken}"; # override ipv6 for lan20, since the Att box uses ::1 here
|
||||||
};
|
};
|
||||||
lan30 = mkIfConfig {
|
lan30 = mkIfConfig {
|
||||||
name_ = "${lan.name}.30";
|
name_ = "${lan.name}.30";
|
@ -1,6 +1,6 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
let
|
let
|
||||||
vars = import ./vars.nix;
|
vars = import ./vars.nix config;
|
||||||
wg0 = vars.ifs.wg0;
|
wg0 = vars.ifs.wg0;
|
||||||
|
|
||||||
peerIps = ifObj: token: [
|
peerIps = ifObj: token: [
|
Loading…
x
Reference in New Issue
Block a user