diff options
| author | Isabella Morgana Bastaja <isabella@sorre.xyz> | 2026-05-23 19:00:22 +0200 |
|---|---|---|
| committer | Isabella Morgana Bastaja <isabella@sorre.xyz> | 2026-05-23 19:04:19 +0200 |
| commit | ff57ba7ef989b8c6828dffddf06eea1f15866f92 (patch) | |
| tree | cbdcd437c435dcb82b0a6179acfdcb4295b1cf70 /hosts/nyaan | |
| parent | 21eece84948ea2de30e73f39adf5fc571950ad08 (diff) | |
WIP: create wireguard network
Diffstat (limited to 'hosts/nyaan')
| -rw-r--r-- | hosts/nyaan/default.nix | 1 | ||||
| -rw-r--r-- | hosts/nyaan/wireguard.nix | 62 |
2 files changed, 63 insertions, 0 deletions
diff --git a/hosts/nyaan/default.nix b/hosts/nyaan/default.nix index af37dbc..d8c2291 100644 --- a/hosts/nyaan/default.nix +++ b/hosts/nyaan/default.nix @@ -9,6 +9,7 @@ # Include the results of the hardware scan. ./hardware.nix + ./wireguard.nix ./home.nix (flakeRoot + /share/system/client-common.nix) { diff --git a/hosts/nyaan/wireguard.nix b/hosts/nyaan/wireguard.nix new file mode 100644 index 0000000..a154f5b --- /dev/null +++ b/hosts/nyaan/wireguard.nix @@ -0,0 +1,62 @@ +{ config, ... }: +let + # NOTE: port is the same on every host + port = 51820; +in +{ + sops = { + age.keyFile = "/var/lib/sops-nix/key.txt"; + secrets = { + "wg-priv-key" = { + sopsFile = ../../secrets/wg-nyaan-private.txt; + owner = "systemd-networkd"; + group = "systemd-networkd"; + mode = "0640"; + format = "binary"; + }; + }; + }; + + networking.firewall.allowedUDPPorts = [ port ]; + networking.useNetworkd = true; + + systemd.network = { + enable = true; + networks."50-wg" = { + matchConfig.Name = "wg0"; + address = [ + "2301:db8:acad:a::2/128" + "192.168.5.2/32" + ]; + }; + netdevs."50-wg" = { + netdevConfig = { + Kind = "wireguard"; + Name = "wg0"; + }; + + wireguardConfig = { + ListenPort = port; + PrivateKeyFile = config.sops.secrets."wg-priv-key".path; + # To automatically create routes for everything in AllowedIPs, + # add RouteTable=main + RouteTable = "main"; + # FirewallMark marks all packets send and received by wg0 with the + # number 42, which can be used to define policy rules on these packets. + FirewallMark = 42; + }; + + wireguardPeers = [ + { + # sagittarius + PublicKey = "u5nh+YNV84IbS7g0ncfs/V+cqEudNh500LQ7pmdS7j0="; + AllowedIPs = [ + "2301:db8:acad:a::1/128" + "192.168.5.1/32" + ]; + Endpoint = "95.216.136.85:${port}"; + } + ]; + }; + }; +} |
