Compare commits
6 Commits
25b2e3e05f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae82eaa500 | ||
|
|
e24e96f091 | ||
|
|
b42579f8cd | ||
|
|
0192a1ace0 | ||
|
|
dcc5c440f7 | ||
|
|
1ceb440026 |
@@ -1,4 +1,21 @@
|
|||||||
{ config, lib, pkgs, ... }: {
|
{ config, lib, pkgs, ... }: let
|
||||||
|
systemsDir = ../../../../../systems;
|
||||||
|
systemNames = lib.attrNames (lib.filterAttrs
|
||||||
|
(name: type: type == "directory" && builtins.pathExists (systemsDir + "/${name}/cfg.nix"))
|
||||||
|
(builtins.readDir systemsDir));
|
||||||
|
|
||||||
|
# Use a helper to check if the attribute path exists safely
|
||||||
|
# This prevents the "attribute 'net' missing" error
|
||||||
|
isValidPeer = p:
|
||||||
|
(p ? syscfg.net.wg.enable) &&
|
||||||
|
(p.syscfg.net.wg.enable == true) &&
|
||||||
|
(p.syscfg.net.wg.pubkey != config.syscfg.net.wg.pubkey);
|
||||||
|
|
||||||
|
importedConfigs = map (name: import (systemsDir + "/${name}/cfg.nix")) systemNames;
|
||||||
|
|
||||||
|
activePeers = builtins.filter isValidPeer importedConfigs;
|
||||||
|
in
|
||||||
|
{
|
||||||
imports = [ ./forwarding.nix ];
|
imports = [ ./forwarding.nix ];
|
||||||
config = lib.mkIf (config.syscfg.net.wg.enable) {
|
config = lib.mkIf (config.syscfg.net.wg.enable) {
|
||||||
networking.wireguard = {
|
networking.wireguard = {
|
||||||
@@ -10,18 +27,13 @@
|
|||||||
config.sops.secrets."${config.syscfg.hostname}_wg_priv".path;
|
config.sops.secrets."${config.syscfg.hostname}_wg_priv".path;
|
||||||
listenPort = 1515;
|
listenPort = 1515;
|
||||||
mtu = 1340;
|
mtu = 1340;
|
||||||
postSetup = if config.syscfg.net.wg.server.enable then ''
|
|
||||||
for keyfile in /run/secrets/*_wg_pub; do
|
|
||||||
if [ -f "$keyfile" ]; then
|
|
||||||
${pkgs.wireguard-tools}/bin/wg set wg0 \
|
|
||||||
peer "$(cat "$keyfile")" \
|
|
||||||
allowed-ips 10.10.1.0/24,fd10:10:10::0/64
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
'' else '''';
|
|
||||||
peers =
|
peers =
|
||||||
if config.syscfg.net.wg.server.enable then
|
if config.syscfg.net.wg.server.enable then
|
||||||
[]
|
map (p: {
|
||||||
|
name = p.syscfg.hostname;
|
||||||
|
publicKey = p.syscfg.net.wg.pubkey;
|
||||||
|
allowedIPs = [ p.syscfg.net.wg.ip4 p.syscfg.net.wg.ip6 ];
|
||||||
|
}) activePeers
|
||||||
else
|
else
|
||||||
[{
|
[{
|
||||||
allowedIPs = [ "10.10.1.0/24" "fd10:10:10::0/64" ];
|
allowedIPs = [ "10.10.1.0/24" "fd10:10:10::0/64" ];
|
||||||
|
|||||||
@@ -16,5 +16,4 @@
|
|||||||
group = config.users.users.${config.syscfg.defaultUser}.group;
|
group = config.users.users.${config.syscfg.defaultUser}.group;
|
||||||
};
|
};
|
||||||
sops.secrets."${config.syscfg.hostname}_wg_priv" = { };
|
sops.secrets."${config.syscfg.hostname}_wg_priv" = { };
|
||||||
sops.secrets."${config.syscfg.hostname}_wg_pub" = { };
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -28,12 +28,7 @@ in {
|
|||||||
group = config.users.users.${config.syscfg.defaultUser}.group;
|
group = config.users.users.${config.syscfg.defaultUser}.group;
|
||||||
};
|
};
|
||||||
"${config.syscfg.hostname}_wg_priv" = { };
|
"${config.syscfg.hostname}_wg_priv" = { };
|
||||||
"${config.syscfg.hostname}_wg_pub" = { };
|
|
||||||
}
|
}
|
||||||
(lib.genAttrs
|
|
||||||
(map (peer: "${peer}_wg_pub") config.syscfg.net.wg.server.peers)
|
|
||||||
(_: { mode = "0444"; })
|
|
||||||
)
|
|
||||||
(lib.genAttrs
|
(lib.genAttrs
|
||||||
(map (peer: "${peer}_ssh_pub") ["iriy" "avalon" "valinor"])
|
(map (peer: "${peer}_ssh_pub") ["iriy" "avalon" "valinor"])
|
||||||
(_: { mode = "0444"; })
|
(_: { mode = "0444"; })
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ let
|
|||||||
type = types.str;
|
type = types.str;
|
||||||
default = "";
|
default = "";
|
||||||
};
|
};
|
||||||
|
pubkey = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "";
|
||||||
|
};
|
||||||
server = {
|
server = {
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
|
|||||||
@@ -26,10 +26,13 @@
|
|||||||
cli = true;
|
cli = true;
|
||||||
virt = true;
|
virt = true;
|
||||||
};
|
};
|
||||||
wg = {
|
net = {
|
||||||
enable = true;
|
wg = {
|
||||||
ip4 = "10.10.1.2/32";
|
enable = true;
|
||||||
ip6 = "fd10:10:10::2/128";
|
ip4 = "10.10.1.2/32";
|
||||||
|
ip6 = "fd10:10:10::2/128";
|
||||||
|
pubkey = "QlvpTiK6s/lIha9vKmo+teSy2Nw52qWLYatYjxVan3U=";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
enable = true;
|
enable = true;
|
||||||
ip4 = "10.10.1.1/32";
|
ip4 = "10.10.1.1/32";
|
||||||
ip6 = "fd10:10:10::1/128";
|
ip6 = "fd10:10:10::1/128";
|
||||||
|
pubkey = "NFBJvYXZC+bd62jhrKnM7/pugidWhgR6+C5qIiUiq3Q=";
|
||||||
server = {
|
server = {
|
||||||
enable = true;
|
enable = true;
|
||||||
peers = ["avalon" "iriy" "valinor"];
|
peers = ["avalon" "iriy" "valinor"];
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{ config, inputs, ... }: {
|
{ config, lib, inputs, ... }: {
|
||||||
imports = [ ./hardware.nix ];
|
imports = [ ./hardware.nix ];
|
||||||
|
|
||||||
services.openssh.enable = true;
|
services.openssh.enable = true;
|
||||||
services.openssh.authorizedKeysFiles = [
|
services.openssh.authorizedKeysFiles = [
|
||||||
config.sops.secrets."iriy_ssh_pub".path
|
config.sops.secrets."iriy_ssh_pub".path
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
{ config, lib, pkgs, modulesPath, ... }: {
|
{ config, lib, pkgs, modulesPath, ... }: {
|
||||||
boot.kernelPackages = pkgs.linuxPackages_latest;
|
boot.kernelPackages = pkgs.linuxPackages_latest;
|
||||||
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
|
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
|
||||||
boot.loader.grub.device = "/dev/sda";
|
|
||||||
|
boot.loader.systemd-boot.enable = lib.mkForce false;
|
||||||
|
boot.loader.efi.canTouchEfiVariables = lib.mkForce false;
|
||||||
|
boot.loader.grub = {
|
||||||
|
enable = true;
|
||||||
|
device = "/dev/sda";
|
||||||
|
efiSupport = true;
|
||||||
|
efiInstallAsRemovable = true;# CRITICAL: This overwrites /boot/EFI/BOOT/BOOTX64.EFI
|
||||||
|
};
|
||||||
|
|
||||||
boot.initrd.availableKernelModules =
|
boot.initrd.availableKernelModules =
|
||||||
[ "ata_piix" "uhci_hcd" "xen_blkfront" "vmw_pvscsi" ];
|
[ "ata_piix" "uhci_hcd" "xen_blkfront" "vmw_pvscsi" ];
|
||||||
boot.initrd.kernelModules = [ "nvme" ];
|
boot.initrd.kernelModules = [ "nvme" ];
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
enable = true;
|
enable = true;
|
||||||
ip4 = "10.10.1.7/32";
|
ip4 = "10.10.1.7/32";
|
||||||
ip6 = "fd10:10:10::7/128";
|
ip6 = "fd10:10:10::7/128";
|
||||||
|
pubkey = "6d1bINFmH12ACAJLDOwfFIZgmNHV/FGGk0YJyDP50HQ=";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
enable = true;
|
enable = true;
|
||||||
ip4 = "10.10.1.5/32";
|
ip4 = "10.10.1.5/32";
|
||||||
ip6 = "fd10:10:10::5/128";
|
ip6 = "fd10:10:10::5/128";
|
||||||
|
pubkey = "EUYd/dMdGcbxiWJXHhQhCXV00cr87pxiW1HExwCTGg0=";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user