7 Commits

14 changed files with 201 additions and 520 deletions

47
flake.lock generated
View File

@@ -7,11 +7,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1747009742, "lastModified": 1740432748,
"narHash": "sha256-TNhbM7R45fpq2cdWzvFj+H5ZTcE//I5XSe78GFh0cDY=", "narHash": "sha256-BCeFtoJ/+LrZc03viRJWHfzAqqG8gPu/ikZeurv05xs=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "c74665abd6e4e37d3140e68885bc49a994ffa53c", "rev": "c12dcc9b61429b2ad437a7d4974399ad8f910319",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -43,11 +43,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1742568034, "lastModified": 1737057290,
"narHash": "sha256-QaMEhcnscfF2MqB7flZr+sLJMMYZPnvqO4NYf9B4G38=", "narHash": "sha256-3Pe0yKlCc7EOeq1X/aJVDH0CtNL+tIBm49vpepwL1MQ=",
"owner": "nix-community", "owner": "nix-community",
"repo": "nixos-generators", "repo": "nixos-generators",
"rev": "42ee229088490e3777ed7d1162cb9e9d8c3dbb11", "rev": "d002ce9b6e7eb467cd1c6bb9aef9c35d191b5453",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -58,11 +58,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1746904237, "lastModified": 1740367490,
"narHash": "sha256-3e+AVBczosP5dCLQmMoMEogM57gmZ2qrVSrmq9aResQ=", "narHash": "sha256-WGaHVAjcrv+Cun7zPlI41SerRtfknGQap281+AakSAw=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "d89fc19e405cb2d55ce7cc114356846a0ee5e956", "rev": "0196c0175e9191c474c26ab5548db27ef5d34b05",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -82,11 +82,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1742765550, "lastModified": 1739557722,
"narHash": "sha256-2vVIh2JrL6GAGfgCeY9e6iNKrBjs0Hw3bGQEAbwVs68=", "narHash": "sha256-XikzLpPUDYiNyJ4w2SfRShdbSkIgE3btYdxCGInmtc4=",
"owner": "nix-community", "owner": "nix-community",
"repo": "plasma-manager", "repo": "plasma-manager",
"rev": "b70be387276e632fe51232887f9e04e2b6ef8c16", "rev": "1f3e1f38dedbbb8aad77e184fb54ec518e2d9522",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -100,28 +100,7 @@
"home-manager": "home-manager", "home-manager": "home-manager",
"nixos-generators": "nixos-generators", "nixos-generators": "nixos-generators",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"plasma-manager": "plasma-manager", "plasma-manager": "plasma-manager"
"secrix": "secrix"
}
},
"secrix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1746643487,
"narHash": "sha256-dcB/DArJObCvqE/ZEdQSDW2BZMeDyF83Se5KPfJvz60=",
"owner": "Platonic-Systems",
"repo": "secrix",
"rev": "4c64203fa5b377953b1fb6d5388187df8b60c6d5",
"type": "github"
},
"original": {
"owner": "Platonic-Systems",
"repo": "secrix",
"type": "github"
} }
} }
}, },

View File

@@ -18,15 +18,9 @@
url = "github:nix-community/nixos-generators"; url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
secrix = {
url = "github:Platonic-Systems/secrix";
inputs.nixpkgs.follows = "nixpkgs";
};
}; };
outputs = { self, nixpkgs, home-manager, plasma-manager, nixos-generators, secrix }: { outputs = { self, nixpkgs, home-manager, plasma-manager, nixos-generators }: {
apps.x86_64-linux.secrix = secrix.secrix self;
nixosConfigurations = { nixosConfigurations = {
Yura-PC = nixpkgs.lib.nixosSystem { Yura-PC = nixpkgs.lib.nixosSystem {
system = "x86_64-linux"; system = "x86_64-linux";
@@ -58,7 +52,6 @@
router = nixpkgs.lib.nixosSystem { router = nixpkgs.lib.nixosSystem {
system = "x86_64-linux"; system = "x86_64-linux";
modules = [ modules = [
secrix.nixosModules.default
./modules ./modules
./hosts/common.nix ./hosts/common.nix
./hosts/router ./hosts/router

View File

@@ -19,7 +19,6 @@ in
SHELL = "fish"; SHELL = "fish";
}; };
# TODO: remove (replace by bitwarden-desktop)
services.gnome-keyring = { services.gnome-keyring = {
enable = true; enable = true;
components = [ "pkcs11" "ssh" ]; components = [ "pkcs11" "ssh" ];
@@ -49,14 +48,14 @@ in
ll = "exa -l --color=always --group-directories-first --icons"; # long format ll = "exa -l --color=always --group-directories-first --icons"; # long format
lt = "exa -aT --color=always --group-directories-first --icons"; # tree listing lt = "exa -aT --color=always --group-directories-first --icons"; # tree listing
"l." = "exa -a | rg '^\.'"; # show only dotfiles "l." = "exa -a | rg '^\.'"; # show only dotfiles
# Replace cat with bat # Replace cat with bat
cat = "bat"; cat = "bat";
}; };
# alias for nix shell with flake packages # alias for nix shell with flake packages
functions.add.body = '' functions.add.body = ''
set -x packages 'nixpkgs#'$argv set -x packages 'nixpkgs#'(string join ' nixpkgs#' $argv)
nix shell $packages nix shell $packages --command fish
''; '';
interactiveShellInit = '' interactiveShellInit = ''
fastfetch fastfetch
@@ -162,7 +161,6 @@ in
shellExpand = true; shellExpand = true;
}; };
dolphinrc.General.ShowFullPath = true; dolphinrc.General.ShowFullPath = true;
dolphinrc.DetailsMode.PreviewSize.persistent = true;
kactivitymanagerdrc = { kactivitymanagerdrc = {
activities."809dc779-bf5b-49e6-8e3f-cbe283cb05b6" = "Default"; activities."809dc779-bf5b-49e6-8e3f-cbe283cb05b6" = "Default";
activities."b34a506d-ac4f-4797-8c08-6ef45bc49341" = "Fun"; activities."b34a506d-ac4f-4797-8c08-6ef45bc49341" = "Fun";

View File

@@ -32,7 +32,7 @@
boot.loader.timeout = 3; boot.loader.timeout = 3;
boot.loader.systemd-boot.configurationLimit = 5; boot.loader.systemd-boot.configurationLimit = 5;
boot.kernelPackages = pkgs.linuxKernel.packages.linux_6_13; boot.kernelPackages = pkgs.linuxKernel.packages.linux_6_12;
# https://nixos.wiki/wiki/Accelerated_Video_Playback # https://nixos.wiki/wiki/Accelerated_Video_Playback
hardware.graphics = { hardware.graphics = {
@@ -125,7 +125,6 @@
# Nix # Nix
nixd nixd
nil
# Gleam # Gleam
gleam gleam
@@ -160,7 +159,7 @@
# https://discourse.nixos.org/t/firefox-does-not-use-kde-window-decorations-and-cursor/32132/3 # https://discourse.nixos.org/t/firefox-does-not-use-kde-window-decorations-and-cursor/32132/3
# programs.dconf.enable = true; # programs.dconf.enable = true;
# programs.firefox = { # programs.firefox = {
# enable = true; # enable = true;
# preferences = { # preferences = {
# "widget.use-xdg-desktop-portal.file-picker" = 1; # "widget.use-xdg-desktop-portal.file-picker" = 1;
@@ -179,9 +178,9 @@
programs.nix-ld.enable = true; programs.nix-ld.enable = true;
programs.nix-ld.libraries = with pkgs; [ programs.nix-ld.libraries = with pkgs; [
# Add any missing dynamic libraries for unpackaged # Add any missing dynamic libraries for unpackaged
# programs here, NOT in environment.systemPackages # programs here, NOT in environment.systemPackages
# For JetBrains stuff # For JetBrains stuff
# https://github.com/NixOS/nixpkgs/issues/240444 # https://github.com/NixOS/nixpkgs/issues/240444
]; ];
@@ -208,54 +207,24 @@
]; ];
# fonts.fontDir.enable = true; # fonts.fontDir.enable = true;
# fonts.fontconfig.allowBitmaps = false; # fonts.fontconfig.allowBitmaps = false;
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
darkman
dust dust
efibootmgr
eza eza
fastfetch fastfetch
fd fd
helix
micro
ripgrep
starship
tealdeer
] ++ [
efibootmgr
ffmpeg ffmpeg
file
fq
gnumake
ijq
jq
ldns
mediainfo
rbw
restic
resticprofile
rclone
ripgrep-all
rustscan
whois
yt-dlp
] ++ [
bitwarden-desktop
darkman
host-spawn # for flatpaks host-spawn # for flatpaks
kdePackages.filelight kdePackages.filelight
kdePackages.flatpak-kcm kdePackages.flatpak-kcm
kdePackages.kate kdePackages.kate
kdePackages.yakuake kdePackages.yakuake
# TODO: remove (replace by bitwarden-desktop)
gcr gcr
gnome-keyring # config for this and some others gnome-keyring # config for this and some others
mpv gnumake
nextcloud-client helix
lxqt.pavucontrol-qt
pinentry
tela-circle-icon-theme
virt-viewer
waypipe
] ++ [
# jetbrains.rust-rover # jetbrains.rust-rover
# jetbrains.goland # jetbrains.goland
jetbrains.clion jetbrains.clion
@@ -263,8 +232,22 @@
jetbrains.pycharm-professional jetbrains.pycharm-professional
jetbrains.webstorm jetbrains.webstorm
android-studio android-studio
mediainfo
micro
mpv
nextcloud-client
lxqt.pavucontrol-qt
pinentry
rbw
ripgrep
rustup rustup
zed-editor starship
tealdeer
tela-circle-icon-theme
virt-viewer
waypipe
whois
yt-dlp
]; ];
# Some programs need SUID wrappers, can be configured further or are # Some programs need SUID wrappers, can be configured further or are

View File

@@ -1,8 +1,5 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let
vars = import ./vars.nix;
enableDesktop = false;
in
{ {
imports = imports =
[ # Include the results of the hardware scan. [ # Include the results of the hardware scan.
@@ -11,11 +8,8 @@ in
./firewall.nix ./firewall.nix
./dns.nix ./dns.nix
./kea.nix ./kea.nix
./glance.nix
./services.nix ./services.nix
]; ];
# Secrix for secrets management
secrix.hostPubKey = vars.pubkey;
# Bootloader. # Bootloader.
boot.loader.systemd-boot.enable = true; boot.loader.systemd-boot.enable = true;
@@ -37,10 +31,10 @@ in
# Enable the KDE Plasma Desktop Environment. # Enable the KDE Plasma Desktop Environment.
# Useful for debugging with wireshark. # Useful for debugging with wireshark.
# services.displayManager.sddm.enable = true;
hardware.graphics.enable = true; hardware.graphics.enable = true;
services.displayManager.sddm.enable = enableDesktop; services.displayManager.sddm.wayland.enable = true;
services.displayManager.sddm.wayland.enable = enableDesktop; services.desktopManager.plasma6.enable = true;
services.desktopManager.plasma6.enable = enableDesktop;
# No need for audio in VM # No need for audio in VM
services.pipewire.enable = false; services.pipewire.enable = false;
@@ -85,7 +79,9 @@ in
eza eza
fastfetch fastfetch
fd fd
kdePackages.filelight
kdePackages.kate kdePackages.kate
kdePackages.yakuake
ldns ldns
lsof lsof
micro micro

View File

@@ -42,23 +42,11 @@ in
services.adguardhome.enable = true; services.adguardhome.enable = true;
services.adguardhome.mutableSettings = false; services.adguardhome.mutableSettings = false;
# https://github.com/AdguardTeam/Adguardhome/wiki/Configuration
services.adguardhome.settings = { services.adguardhome.settings = {
dns = { dns = {
# Disable rate limit, default of 20 is too low
# https://github.com/AdguardTeam/AdGuardHome/issues/6726
ratelimit = 0;
bootstrap_dns = [ "1.1.1.1" "9.9.9.9" ]; bootstrap_dns = [ "1.1.1.1" "9.9.9.9" ];
upstream_dns = [ upstream_dns = [
# Default upstreams "quic://p0.freedns.controld.com" # Default upstream
"quic://p0.freedns.controld.com"
"tls://one.one.one.one"
"tls://dns.quad9.net"
# Adguard uses upstream and not rewrite rules to resolve cname rewrites,
# and obviously my sysdomain entries don't exist in cloudflare.
"[/${sysdomain}/][::1]" # Sys domains to self (for cname rewrites)
"[/${ldomain}/][::1]:1053" # Local domains to Knot (ddns) "[/${ldomain}/][::1]:1053" # Local domains to Knot (ddns)
"[/home/][${ifs.lan.ulaPrefix}::250]" # .home domains to opnsense (temporary) "[/home/][${ifs.lan.ulaPrefix}::250]" # .home domains to opnsense (temporary)
]; ];
@@ -68,30 +56,26 @@ in
# DNS rewrites # DNS rewrites
"|grouter.${domain}^$dnsrewrite=${ifs.lan.ulaAddr}" "|grouter.${domain}^$dnsrewrite=${ifs.lan.ulaAddr}"
"|pve-1.${sysdomain}^$dnsrewrite=${ifs.lan.p4}.5" "|pve-1.${sysdomain}^$dnsrewrite=${ifs.lan.p4}.5"
"|pve-1.${sysdomain}^$dnsrewrite=${ifs.lan.ulaPrefix}::5:1"
"|pve-3.${sysdomain}^$dnsrewrite=${ifs.lan.p4}.7" "|pve-3.${sysdomain}^$dnsrewrite=${ifs.lan.p4}.7"
"|pve-1.${sysdomain}^$dnsrewrite=${ifs.lan.ulaPrefix}::5:1"
"|pve-3.${sysdomain}^$dnsrewrite=${ifs.lan.ulaPrefix}::7:1" "|pve-3.${sysdomain}^$dnsrewrite=${ifs.lan.ulaPrefix}::7:1"
"|truenas.${sysdomain}^$dnsrewrite=${ifs.lan.p4}.10"
"|truenas.${sysdomain}^$dnsrewrite=${ifs.lan.ulaPrefix}::20d0:43ff:fec6:3192"
"|debbi.${sysdomain}^$dnsrewrite=${ifs.lan.p4}.11"
"|debbi.${sysdomain}^$dnsrewrite=${ifs.lan.ulaPrefix}::11:1"
"|etappi.${sysdomain}^$dnsrewrite=${ifs.lan.p4}.12"
"|etappi.${sysdomain}^$dnsrewrite=${ifs.lan.ulaPrefix}::12:1"
# Lab DNS rewrites "||lab.${domain}^$dnsrewrite=${ifs.lan.p6}::12:1"
"||lab.${domain}^$dnsrewrite=etappi.${sysdomain}" "||lab.${domain}^$dnsrewrite=${ifs.lan.p4}.12"
# Allowed exceptions # Allowed exceptions
"@@||googleads.g.doubleclick.net" "@@||googleads.g.doubleclick.net"
] ]
# Alpina DNS rewrites # Alpina DNS rewrites
++ map (host: "${host}${domain}^$dnsrewrite=debbi.${sysdomain}") alpinaDomains; ++ map (host: "${host}${domain}^$dnsrewrite=${ifs.lan.p6}:1cd5:56ff:feec:c74a") alpinaDomains
++ map (host: "${host}${domain}^$dnsrewrite=${ifs.lan.p4}.11") alpinaDomains;
}; };
services.knot.enable = true; services.knot.enable = true;
services.knot.settings = { services.knot.settings = {
# server.listen = "0.0.0.0@1053"; # server.listen = "0.0.0.0@1053";
server.listen = "::1@1053"; server.listen = "::1@1053";
# TODO: templates
zone = [ zone = [
{ {
domain = ldomain; domain = ldomain;

View File

@@ -1,104 +1,45 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let let
vars = import ./vars.nix; vars = import ./vars.nix;
domain = vars.domain;
ldomain = vars.ldomain;
sysdomain = vars.sysdomain;
links = vars.links; links = vars.links;
ifs = vars.ifs; ifs = vars.ifs;
pdFromWan = vars.pdFromWan; pdFromWan = vars.pdFromWan;
nftIdentifiers = ''
define ZONE_WAN_IFS = { ${ifs.wan.name} }
define ZONE_LAN_IFS = {
${ifs.lan.name},
${ifs.lan10.name},
${ifs.lan20.name},
${ifs.lan30.name},
${ifs.lan40.name},
${ifs.lan50.name},
}
define OPNSENSE_NET6 = ${vars.extra.opnsense.net6}
define ZONE_LAN_EXTRA_NET6 = {
# TODO: reevaluate this statement
${ifs.lan20.net6}, # needed since packets can come in from wan on these addrs
$OPNSENSE_NET6,
}
define RFC1918 = { 10.0.0.0/8, 172.12.0.0/12, 192.168.0.0/16 }
define CLOUDFLARE_NET6 = {
# https://www.cloudflare.com/ips-v6
# TODO: figure out a better way to get addrs dynamically from url
# perhaps building a nixos module/package that fetches the ips?
2400:cb00::/32,
2606:4700::/32,
2803:f800::/32,
2405:b500::/32,
2405:8100::/32,
2a06:98c0::/29,
2c0f:f248::/32,
}
'';
in in
{ {
networking.firewall.enable = false; networking.firewall.enable = false;
networking.nftables.enable = true; networking.nftables.enable = true;
# networking.nftables.ruleset = nftIdentifiers; #doesn't work because it's appended to the end networking.nftables.tables.firewall = {
networking.nftables.tables.nat4 = { family = "inet";
family = "ip";
content = '' content = ''
${nftIdentifiers} define ZONE_WAN_IFS = { ${ifs.wan.name} }
map port_forward { define ZONE_LAN_IFS = {
${ifs.lan.name},
${ifs.lan10.name},
${ifs.lan20.name},
${ifs.lan30.name},
${ifs.lan40.name},
${ifs.lan50.name},
}
define OPNSENSE_P6 = ${pdFromWan}d::/64
define RFC1918 = { 10.0.0.0/8, 172.12.0.0/12, 192.168.0.0/16 }
define ALLOWED_TCP_PORTS = { ssh, https }
define ALLOWED_UDP_PORTS = { bootps, dhcpv6-server, domain }
map port_forward_v4 {
type inet_proto . inet_service : ipv4_addr . inet_service type inet_proto . inet_service : ipv4_addr . inet_service
elements = { elements = {
tcp . 8006 : ${ifs.lan50.p4}.10 . 8006 tcp . 8006 : ${ifs.lan50.p4}.10 . 8006
} }
} }
chain prerouting {
# Initial step, accept by default
type nat hook prerouting priority dstnat; policy accept;
# Port forwarding
fib daddr type local dnat ip to meta l4proto . th dport map @port_forward
}
chain postrouting {
# Last step, accept by default
type nat hook postrouting priority srcnat; policy accept;
# Masquerade LAN addrs
oifname $ZONE_WAN_IFS ip saddr $RFC1918 masquerade
}
'';
};
# Optional IPv6 masquerading (big L if enabled, don't forget to allow forwarding)
networking.nftables.tables.nat6 = {
family = "ip6";
enable = false;
content = ''
${nftIdentifiers}
chain postrouting {
type nat hook postrouting priority srcnat; policy accept;
oifname $ZONE_WAN_IFS ip6 saddr fd00::/8 masquerade
}
'';
};
networking.nftables.tables.firewall = {
family = "inet";
content = ''
${nftIdentifiers}
define ALLOWED_TCP_PORTS = { ssh, https }
define ALLOWED_UDP_PORTS = { bootps, dhcpv6-server, domain, https }
set port_forward_v6 { set port_forward_v6 {
type inet_proto . ipv6_addr . inet_service type inet_proto . ipv6_addr . inet_service
elements = { elements = {
# syncthing on alpina tcp . ${ifs.lan.p6}::11:1 . https,
tcp . ${ifs.lan.p6}::11:1 . 22000 , tcp . ${ifs.lan.p6}:1cd5:56ff:feec:c74a . https,
udp . ${ifs.lan.p6}::11:1 . 22000 ,
}
}
set cloudflare_forward_v6 {
type ipv6_addr
elements = {
${ifs.lan.p6}::11:1,
} }
} }
@@ -108,9 +49,7 @@ in
# Drop router adverts from self # Drop router adverts from self
# peculiarity due to wan and lan20 being bridged # peculiarity due to wan and lan20 being bridged
# TODO: figure out a less jank way to do this # TODO: figure out a less jank way to do this
iifname $ZONE_WAN_IFS ip6 saddr ${links.lanLL} icmpv6 type nd-router-advert log prefix "self radvt: " drop iifname $ZONE_WAN_IFS ip6 saddr ${links.lanLL} icmpv6 type nd-router-advert log drop
# iifname $ZONE_WAN_IFS ip6 saddr ${links.lanLL} ip6 nexthdr icmpv6 log prefix "self icmpv6: " drop
# iifname $ZONE_WAN_IFS ip6 saddr ${links.lanLL} log prefix "self llv6: " drop
# iifname $ZONE_WAN_IFS ip6 saddr ${links.lanLL} log drop # iifname $ZONE_WAN_IFS ip6 saddr ${links.lanLL} log drop
# iifname $ZONE_LAN_IFS ip6 saddr ${links.wanLL} log drop # iifname $ZONE_LAN_IFS ip6 saddr ${links.wanLL} log drop
@@ -128,19 +67,17 @@ in
# Allow all traffic from loopback interface # Allow all traffic from loopback interface
iif lo accept iif lo accept
# Allow DHCPv6 traffic # Allow DHCPv6 client traffic
# I thought dhcpv6-client traffic would be accepted by established/related, ip6 daddr { fe80::/10, ff02::/16 } th dport dhcpv6-server accept
# but apparently not.
ip6 daddr { fe80::/10, ff02::/16 } th dport { dhcpv6-client, dhcpv6-server } accept
# WAN zone input rules # WAN zone input rules
iifname $ZONE_WAN_IFS jump zone_wan_input iifname $ZONE_WAN_IFS jump zone_wan_input
# LAN zone input rules # LAN zone input rules
# iifname $ZONE_LAN_IFS accept iifname $ZONE_LAN_IFS accept
iifname $ZONE_LAN_IFS jump zone_lan_input iifname $ZONE_LAN_IFS jump zone_lan_input
ip6 saddr $ZONE_LAN_EXTRA_NET6 jump zone_lan_input ip6 saddr $OPNSENSE_P6 jump zone_lan_input
# log log
} }
chain forward { chain forward {
@@ -153,7 +90,7 @@ in
iifname $ZONE_WAN_IFS jump zone_wan_forward iifname $ZONE_WAN_IFS jump zone_wan_forward
# LAN zone forward rules # LAN zone forward rules
iifname $ZONE_LAN_IFS jump zone_lan_forward iifname $ZONE_LAN_IFS jump zone_lan_forward
ip6 saddr $ZONE_LAN_EXTRA_NET6 jump zone_lan_forward ip6 saddr $OPNSENSE_P6 jump zone_lan_forward
} }
chain zone_wan_input { chain zone_wan_input {
@@ -167,9 +104,6 @@ in
# Allowed IPv6 ports # Allowed IPv6 ports
meta l4proto . ip6 daddr . th dport @port_forward_v6 accept meta l4proto . ip6 daddr . th dport @port_forward_v6 accept
# Allowed IPv6 from cloudflare
ip6 saddr $CLOUDFLARE_NET6 ip6 daddr @cloudflare_forward_v6 th dport https accept
} }
chain zone_lan_input { chain zone_lan_input {
@@ -202,6 +136,25 @@ in
# NAT reflection # NAT reflection
# oif lo ip daddr != 127.0.0.0/8 dnat ip to meta l4proto . th dport map @port_forward_v4 # oif lo ip daddr != 127.0.0.0/8 dnat ip to meta l4proto . th dport map @port_forward_v4
} }
chain prerouting {
# Initial step, accept by default
type nat hook prerouting priority dstnat; policy accept;
# Port forwarding
fib daddr type local dnat ip to meta l4proto . th dport map @port_forward_v4
}
chain postrouting {
# Last step, accept by default
type nat hook postrouting priority srcnat; policy accept;
# Masquerade LAN addrs
oifname $ZONE_WAN_IFS ip saddr $RFC1918 masquerade
# Optional IPv6 masquerading (big L if enabled, don't forget to allow forwarding)
# oifname $ZONE_WAN_IFS ip6 saddr fd00::/8 masquerade
}
''; '';
}; };
} }

View File

@@ -1,166 +0,0 @@
{ config, lib, pkgs, ... }:
let
vars = import ./vars.nix;
domain = vars.domain;
in
{
# Glance dashboard
services.glance.enable = true;
services.glance.settings.pages = [
{
name = "Home";
# hideDesktopNavigation = true; # Uncomment if needed
columns = [
{
size = "small";
widgets = [
{
type = "calendar";
firstDayOfWeek = "monday";
}
{
type = "rss";
limit = 10;
collapseAfter = 3;
cache = "12h";
feeds = [
{ url = "https://rtk0c.pages.dev/index.xml"; }
{ url = "https://www.yegor256.com/rss.xml"; }
{ url = "https://selfh.st/rss/"; title = "selfh.st"; }
{ url = "https://ciechanow.ski/atom.xml"; }
{ url = "https://www.joshwcomeau.com/rss.xml"; title = "Josh Comeau"; }
{ url = "https://samwho.dev/rss.xml"; }
{ url = "https://ishadeed.com/feed.xml"; title = "Ahmad Shadeed"; }
];
}
{
type = "twitch-channels";
channels = [
"theprimeagen"
"j_blow"
"piratesoftware"
"cohhcarnage"
"christitustech"
"EJ_SA"
];
}
];
}
{
size = "full";
widgets = [
{
type = "group";
widgets = [
{ type = "hacker-news"; }
{ type = "lobsters"; }
];
}
{
type = "videos";
channels = [
"UCXuqSBlHAE6Xw-yeJA0Tunw" # Linus Tech Tips
"UCR-DXc1voovS8nhAvccRZhg" # Jeff Geerling
"UCsBjURrPoezykLs9EqgamOA" # Fireship
"UCBJycsmduvYEL83R_U4JriQ" # Marques Brownlee
"UCHnyfMqiRRG1u-2MsSQLbXA" # Veritasium
];
}
{
type = "group";
widgets = [
{
type = "reddit";
subreddit = "technology";
showThumbnails = true;
}
{
type = "reddit";
subreddit = "selfhosted";
showThumbnails = true;
}
];
}
];
}
{
size = "small";
widgets = [
{
type = "weather";
location = "San Jose, California, United States";
units = "metric";
hourFormat = "12h";
# hideLocation = true; # Uncomment if needed
}
{
type = "markets";
markets = [
{ symbol = "SPY"; name = "S&P 500"; }
{ symbol = "BTC-USD"; name = "Bitcoin"; }
{ symbol = "NVDA"; name = "NVIDIA"; }
{ symbol = "AAPL"; name = "Apple"; }
{ symbol = "MSFT"; name = "Microsoft"; }
];
}
{
type = "releases";
cache = "1d";
# token = "..."; # Uncomment and set if needed
repositories = [
"glanceapp/glance"
"go-gitea/gitea"
"immich-app/immich"
"syncthing/syncthing"
];
}
];
}
];
}
{
name = "Infrastructure";
columns = [
{
size = "small";
widgets = [
{
type = "server-stats";
servers = [
{
type = "local";
name = "Router";
mountpoints."/nix/store".hide = true;
}
];
}
];
}
{
size = "full";
widgets = [
{
type = "iframe";
title = "Grafana";
title-url = "/grafana/";
source = "/grafana/d-solo/rYdddlPWk/node-exporter-full?orgId=1&from=1747211119196&to=1747297519196&timezone=browser&var-datasource=PBFA97CFB590B2093&var-job=node&var-node=localhost:9100&var-diskdevices=%5Ba-z%5D%2B%7Cnvme%5B0-9%5D%2Bn%5B0-9%5D%2B%7Cmmcblk%5B0-9%5D%2B&refresh=1m&panelId=74&__feature.dashboardSceneSolo";
height = 400;
}
];
}
{
size = "small";
widgets = [
{
type = "dns-stats";
service = "adguard";
url = "http://localhost:${toString config.services.adguardhome.port}";
username = "";
password = "";
}
];
}
];
}
];
}

View File

@@ -18,7 +18,7 @@ let
matchConfig.Name = ifObj.name; matchConfig.Name = ifObj.name;
networkConfig = { networkConfig = {
IPv4Forwarding = true; IPv4Forwarding = true;
IPv6SendRA = true; IPv6SendRA = (ifObj.name != ifs.lan10.name); # TODO: temporary test, remove
Address = [ ifObj.addr4Sized ifObj.addr6Sized ifObj.ulaAddrSized ]; Address = [ ifObj.addr4Sized ifObj.addr6Sized ifObj.ulaAddrSized ];
}; };
ipv6Prefixes = [ ipv6Prefixes = [
@@ -44,55 +44,70 @@ let
DNS = [ ifObj.ulaAddr ]; DNS = [ ifObj.ulaAddr ];
}; };
}; };
in in
{ {
# By default, Linux will respond to ARP requests that belong to other interfaces.
# Normally this isn't a problem, but it causes issues
# since my WAN and LAN20 are technically bridged.
# https://networkengineering.stackexchange.com/questions/83071/why-linux-answers-arp-requests-for-ips-that-belong-to-different-network-interfac
boot.kernel.sysctl."net.ipv4.conf.default.arp_filter" = 1;
# It is impossible to do multiple prefix requests with networkd, # It is impossible to do multiple prefix requests with networkd,
# so I use dhcpcd for this # so I use dhcpcd for this
# https://github.com/systemd/systemd/issues/22571 # https://github.com/systemd/systemd/issues/22571
networking.dhcpcd.enable = true;
# 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.allowInterfaces = [ ifs.wan.name ];
networking.dhcpcd.extraConfig = '' networking.dhcpcd.extraConfig = ''
debug duid
ipv6only
nodhcp6
noipv6rs
nohook resolv.conf, yp, hostname, ntp nohook resolv.conf, yp, hostname, ntp
option rapid_commit
interface ${ifs.wan.name} interface ${ifs.wan.name}
ipv6only
duid
ipv6rs ipv6rs
dhcp6 dhcp6
# option rapid_commit duid
ipv6only
nohook resolv.conf, yp, hostname, ntp
nogateway
option rapid_commit
# DHCPv6 addr # this doesn't play well with networkd
ia_na # ia_na
# ia_pd 1 ${ifs.lan.name}/0
# DHCPv6 Prefix Delegation # ia_pd 2 ${ifs.lan10.name}/0
# ia_pd 3 ${ifs.lan20.name}/0
# request the leases just for routing (so that the att box knows we're here) # request the leases just for routing (so that the att box knows we're here)
# actual ip assignments are static, based on $pdFromWan # actual ip assignments are static, based on $pdFromWan
ia_pd 1/${ifs.lan.net6} - ia_pd 1/${ifs.lan.net6} -
ia_pd 10/${ifs.lan10.net6} - # ia_pd 10/${ifs.lan10.net6} -
# ia_pd 20/${pdFromWan}d::/64 - # for opnsense (legacy services) # ia_pd 20/${pdFromWan}d::/64 - # for opnsense (legacy services)
ia_pd 30/${ifs.lan30.net6} - ia_pd 30/${ifs.lan30.net6} -
ia_pd 40/${ifs.lan40.net6} - ia_pd 40/${ifs.lan40.net6} -
ia_pd 50/${ifs.lan50.net6} - ia_pd 50/${ifs.lan50.net6} -
# ia_pd 7 - # ia_pd 7 -
# ia_pd 8 - # ia_pd 8 -
# the leases can be assigned to the interfaces,
# but this doesn't play well with networkd
# ia_pd 1 ${ifs.lan.name}/0
# ia_pd 2 ${ifs.lan10.name}/0
# ia_pd 3 ${ifs.lan20.name}/0
''; '';
systemd.timers."restart-networkd" = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = "1m";
OnUnitActiveSec = "1m";
Unit = "restart-networkd.service";
};
};
systemd.services."restart-networkd" = {
script = ''
set -eu
${pkgs.systemd}/bin/systemctl restart systemd-networkd
'';
serviceConfig = {
Type = "oneshot";
User = "root";
};
};
networking.useNetworkd = true; networking.useNetworkd = true;
systemd.network.enable = true; systemd.network.enable = true;
systemd.network = { systemd.network = {
@@ -117,7 +132,7 @@ in
}; };
netdevs = { netdevs = {
"10-vlan10" = mkVlanDev { id = 10; name = ifs.lan10.name; }; # "10-vlan10" = mkVlanDev { id = 10; name = ifs.lan10.name; };
"10-vlan20" = mkVlanDev { id = 20; name = ifs.lan20.name; }; "10-vlan20" = mkVlanDev { id = 20; name = ifs.lan20.name; };
"10-vlan30" = mkVlanDev { id = 30; name = ifs.lan30.name; }; "10-vlan30" = mkVlanDev { id = 30; name = ifs.lan30.name; };
"10-vlan40" = mkVlanDev { id = 40; name = ifs.lan40.name; }; "10-vlan40" = mkVlanDev { id = 40; name = ifs.lan40.name; };
@@ -127,8 +142,6 @@ in
networks = { networks = {
"10-wan" = { "10-wan" = {
matchConfig.Name = ifs.wan.name; matchConfig.Name = ifs.wan.name;
# make routing on this interface a dependency for network-online.target
linkConfig.RequiredForOnline = "routable";
networkConfig = { networkConfig = {
# start a DHCP Client for IPv4 Addressing/Routing # start a DHCP Client for IPv4 Addressing/Routing
# DHCP = "ipv4"; # DHCP = "ipv4";
@@ -136,52 +149,76 @@ in
# let dhcpcd handle this # let dhcpcd handle this
Address = [ ifs.wan.addr4Sized ]; Address = [ ifs.wan.addr4Sized ];
IPv6AcceptRA = false; IPv6AcceptRA = false;
KeepConfiguration = true;
}; };
routes = [ routes = [
{ Gateway = ifs.wan.gw4; } { Gateway = ifs.wan.gw4; }
{ Gateway = ifs.wan.gw6; }
]; ];
# make routing on this interface a dependency for network-online.target
linkConfig.RequiredForOnline = "routable";
}; };
"20-lan" = (mkLanConfig ifs.lan) // { "20-lan" = (mkLanConfig ifs.lan) // {
vlan = [ vlan = [
ifs.lan10.name # ifs.lan10.name
ifs.lan20.name ifs.lan20.name
ifs.lan30.name ifs.lan30.name
ifs.lan40.name ifs.lan40.name
ifs.lan50.name ifs.lan50.name
]; ];
routes = vars.extra.opnsense.routes;
}; };
"30-vlan10" = mkLanConfig ifs.lan10; # "30-vlan10" = mkLanConfig ifs.lan10;
"30-vlan20" = mkLanConfig ifs.lan20; "30-vlan20" = mkLanConfig ifs.lan20 // {
routes = [
{
# OPNsense subnet route
Destination = "${pdFromWan}d::/64";
Gateway = "fe80::1efd:8ff:fe71:954e";
}
];
};
"30-vlan30" = mkLanConfig ifs.lan30; "30-vlan30" = mkLanConfig ifs.lan30;
"30-vlan40" = mkLanConfig ifs.lan40; "30-vlan40" = mkLanConfig ifs.lan40;
"30-vlan50" = mkLanConfig ifs.lan50; "30-vlan50" = mkLanConfig ifs.lan50;
}; };
}; };
# For some reason, the interfaces stop receiving route solicitations after a while. networking.interfaces = {
# Regular router adverts still get sent out at intervals, but this breaks dhcp6 clients. # ${ifs.lan10.name} = {
# Restarting networkd makes it work again, I have no clue why. # ipv4.addresses = [ { address = ifs.lan10.addr4; prefixLength = ifs.lan10.p4Size; } ];
# This is jank af, but I've tried a bunch of other stuff with no success # ipv6.addresses = [
# and I'm giving up (for now). # {
systemd.timers."restart-networkd" = { # address = ifs.lan10.addr6;
wantedBy = [ "timers.target" ]; # prefixLength = ifs.lan10.p6Size;
timerConfig = { # }
OnBootSec = "1m"; # {
OnUnitActiveSec = "1m"; # address = ifs.lan10.ulaAddr;
Unit = "restart-networkd.service"; # prefixLength = ifs.lan10.ulaSize;
}; # }
# ];
# };
}; };
networking.dhcpcd.allowInterfaces = [ ifs.wan.name ];
systemd.services."restart-networkd" = { services.radvd.enable = false;
script = '' services.radvd.config = ''
set -eu interface ${ifs.lan10.name} {
${pkgs.systemd}/bin/systemctl restart systemd-networkd RDNSS ${ifs.lan.ulaAddr} {
''; };
serviceConfig = { AdvSendAdvert on;
Type = "oneshot"; # MinRtrAdvInterval 3;
User = "root"; # MaxRtrAdvInterval 10;
AdvManagedFlag on;
# AdvOtherConfigFlag on;
prefix ${ifs.lan10.net6} {
AdvOnLink on;
AdvAutonomous on;
};
prefix ${ifs.lan10.ulaNet} {
AdvOnLink on;
AdvAutonomous on;
};
route ${ulaPrefix}::/48 {
};
}; };
}; '';
} }

View File

@@ -131,7 +131,7 @@ in
services.kea.dhcp4.settings = { services.kea.dhcp4.settings = {
interfaces-config.interfaces = [ interfaces-config.interfaces = [
ifs.lan.name ifs.lan.name
ifs.lan10.name # ifs.lan10.name
ifs.lan20.name ifs.lan20.name
ifs.lan30.name ifs.lan30.name
ifs.lan40.name ifs.lan40.name
@@ -141,7 +141,7 @@ in
ddns-qualifying-suffix = "4.default.${ldomain}"; ddns-qualifying-suffix = "4.default.${ldomain}";
subnet4 = [ subnet4 = [
((mkDhcp4Subnet 1 ifs.lan) // reservations.lan.v4) ((mkDhcp4Subnet 1 ifs.lan) // reservations.lan.v4)
(mkDhcp4Subnet 10 ifs.lan10) # (mkDhcp4Subnet 10 ifs.lan10)
((mkDhcp4Subnet 20 ifs.lan20) // reservations.lan20.v4) ((mkDhcp4Subnet 20 ifs.lan20) // reservations.lan20.v4)
(mkDhcp4Subnet 30 ifs.lan30) (mkDhcp4Subnet 30 ifs.lan30)
(mkDhcp4Subnet 40 ifs.lan40) (mkDhcp4Subnet 40 ifs.lan40)
@@ -153,7 +153,7 @@ in
services.kea.dhcp6.settings = { services.kea.dhcp6.settings = {
interfaces-config.interfaces = [ interfaces-config.interfaces = [
ifs.lan.name ifs.lan.name
ifs.lan10.name # ifs.lan10.name
# ifs.lan20.name # Managed by Att box # ifs.lan20.name # Managed by Att box
ifs.lan30.name ifs.lan30.name
ifs.lan40.name ifs.lan40.name
@@ -164,7 +164,7 @@ in
ddns-qualifying-suffix = "6.default.${ldomain}"; ddns-qualifying-suffix = "6.default.${ldomain}";
subnet6 = [ subnet6 = [
((mkDhcp6Subnet 1 ifs.lan) // reservations.lan.v6) ((mkDhcp6Subnet 1 ifs.lan) // reservations.lan.v6)
(mkDhcp6Subnet 10 ifs.lan10) # (mkDhcp6Subnet 10 ifs.lan10)
(mkDhcp6Subnet 30 ifs.lan30) (mkDhcp6Subnet 30 ifs.lan30)
(mkDhcp6Subnet 40 ifs.lan40) (mkDhcp6Subnet 40 ifs.lan40)
(mkDhcp6Subnet 50 ifs.lan50) (mkDhcp6Subnet 50 ifs.lan50)

View File

@@ -4,10 +4,6 @@ let
domain = vars.domain; domain = vars.domain;
in in
{ {
# vnStat for tracking network interface stats
services.vnstat.enable = true;
# https://wiki.nixos.org/wiki/Prometheus # https://wiki.nixos.org/wiki/Prometheus
services.prometheus = { services.prometheus = {
enable = true; enable = true;
@@ -31,15 +27,7 @@ in
# https://wiki.nixos.org/wiki/Grafana#Declarative_configuration # https://wiki.nixos.org/wiki/Grafana#Declarative_configuration
services.grafana = { services.grafana = {
enable = true; enable = true;
settings = { settings.server.http_port = 3001;
security.allow_embedding = true;
server = {
http_port = 3001;
domain = "grouter.${domain}";
root_url = "https://%(domain)s/grafana/";
serve_from_sub_path = true;
};
};
provision = { provision = {
enable = true; enable = true;
datasources.settings.datasources = [ datasources.settings.datasources = [
@@ -52,34 +40,11 @@ in
}; };
}; };
secrix.system.secrets.cf-api-key.encrypted.file = ../../secrets/cf_api_key.age;
systemd.services.caddy.serviceConfig.EnvironmentFile = config.secrix.system.secrets.cf-api-key.decrypted.path;
services.caddy = { services.caddy = {
enable = true; enable = true;
package = pkgs.caddy.withPlugins {
plugins = [ "github.com/caddy-dns/cloudflare@v0.2.1" ];
hash = "sha256-saKJatiBZ4775IV2C5JLOmZ4BwHKFtRZan94aS5pO90=";
};
virtualHosts."grouter.${domain}".extraConfig = '' virtualHosts."grouter.${domain}".extraConfig = ''
encode reverse_proxy localhost:${toString config.services.grafana.settings.server.http_port}
tls { tls internal
dns cloudflare {env.CF_API_KEY}
resolvers 1.1.1.1
}
@grafana path /grafana /grafana/*
handle @grafana {
reverse_proxy localhost:${toString config.services.grafana.settings.server.http_port}
}
redir /adghome /adghome/
handle_path /adghome/* {
reverse_proxy localhost:${toString config.services.adguardhome.port}
basic_auth {
Bob $2a$14$HsWmmzQTN68K3vwiRAfiUuqIjKoXEXaj9TOLUtG2mO1vFpdovmyBy
}
}
handle /* {
reverse_proxy localhost:${toString config.services.glance.settings.server.port}
}
''; '';
}; };
} }

View File

@@ -31,7 +31,6 @@ let
}; };
in in
rec { rec {
pubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFobB87yYVwhuYrA+tfztLuks3s9jZOqEFktwGw1mo83 root@grouter";
domain = "cazzzer.com"; domain = "cazzzer.com";
ldomain = "l.${domain}"; ldomain = "l.${domain}";
sysdomain = "sys.${domain}"; sysdomain = "sys.${domain}";
@@ -51,6 +50,7 @@ rec {
addr4 = "192.168.1.61"; addr4 = "192.168.1.61";
addr4Sized = "${addr4}/24"; addr4Sized = "${addr4}/24";
gw4 = "192.168.1.254"; gw4 = "192.168.1.254";
gw6 = "fe80::e21f:2bff:fe96:e952";
}; };
lan = mkIfConfig { lan = mkIfConfig {
name_ = "lan"; name_ = "lan";
@@ -96,28 +96,4 @@ rec {
ulaPrefix_ = "${ulaPrefix}:0050"; # ::/64 ulaPrefix_ = "${ulaPrefix}:0050"; # ::/64
}; };
}; };
extra = {
opnsense = rec {
addr4 = "${ifs.lan.p4}.250";
ulaAddr = "${ifs.lan.ulaPrefix}::250";
p6 = "${pdFromWan}d";
net6 = "${p6}::/64";
# VPN routes on opnsense
routes = [
{
Destination = "10.6.0.0/24";
Gateway = addr4;
}
{
Destination = "10.18.0.0/20";
Gateway = addr4;
}
{
Destination = net6;
Gateway = ulaAddr;
}
];
};
};
} }

View File

@@ -1,12 +0,0 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended"
],
"lockFileMaintenance": {
"enabled": true
},
"nix": {
"enabled": true
}
}

View File

@@ -1,5 +0,0 @@
age-encryption.org/v1
-> ssh-ed25519 D2MY/A Kj69kavxx+ATNHP5pX0JtGggU76f9uRwkZp2HbjwiWc
SbU3jIcQzUzaQjRHzVSoW1WKiUj+1ijbkUKqVb406fY
--- vMV0TcchFvxw1xetQQZ0xVi2KwjLFRfZBM1gl7BGbGI
<EFBFBD><EFBFBD>1<10><><EFBFBD><EFBFBD>K<EFBFBD><<3C>