1 { pkgs, lib, config, inputs, hostName, ... }:
3 inherit (config.boot) initrd;
5 peers = import (inputs.julm-nix + "/nixos/profiles/wireguard/${wgIface}/peers.nix");
8 # Open a wireguard tunnel to a relay
9 # in case the host is hosted behind a NAT and has no SSH port forwarding.
10 # This enables to send the disk password to the initrd, like that:
11 # ssh -J mermet.sp root@losurdo.sp -p 2222
12 # TODO: use a dedicated interface wg-initrd
13 security.initrd.secrets."${hostName}/wireguard/${wgIface}/privateKey" =
14 "hosts/${hostName}/wireguard/${wgIface}/privateKey.gpg";
15 boot.initrd.kernelModules = [ "wireguard" ];
16 boot.initrd.network.flushBeforeStage2 = true;
17 boot.initrd.systemd = {
23 services.systemd-networkd = {
24 serviceConfig.LoadCredential = [ "${wgIface}.key:${config.security.initrd.stage1Dir}/${hostName}/wireguard/${wgIface}/privateKey" ];
35 PrivateKeyFile = "/run/credentials/systemd-networkd.service/${wgIface}.key";
36 ListenPort = peers.${hostName}.listenPort;
40 wireguardPeerConfig = with peers.mermet.peer; {
41 AllowedIPs = allowedIPs;
43 PersistentKeepalive = peers.${hostName}.persistentKeepalive;
44 PublicKey = publicKey;
48 wireguardPeerConfig = with peers.oignon.peer; {
49 AllowedIPs = allowedIPs;
50 PersistentKeepalive = peers.${hostName}.persistentKeepalive;
51 PublicKey = publicKey;
57 networks.${wgIface} = {
59 address = peers.${hostName}.ips;
62 IPMasquerade = "ipv4";