From 0a03be14694030f6ca850f90977732a36daf6156 Mon Sep 17 00:00:00 2001 From: Astro Date: Tue, 6 Apr 2021 19:12:22 +0200 Subject: [PATCH] nixos-module/container/anon: setup wireguard --- nix/nixos-module/container/anon.nix | 38 +++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/nix/nixos-module/container/anon.nix b/nix/nixos-module/container/anon.nix index 5651a86..d6db007 100644 --- a/nix/nixos-module/container/anon.nix +++ b/nix/nixos-module/container/anon.nix @@ -1,4 +1,4 @@ -{ hostName, config, lib, ... }: +{ hostName, config, lib, pkgs, ... }: let tunnels = lib.filterAttrs (_: wireguard: @@ -9,29 +9,57 @@ let then builtins.head (builtins.attrNames tunnels) else null; enabled = firstTunnel != null; + privateKeyFile = ifName: + "/run/wireguard-keys/${ifName}.key"; in { + systemd.services = builtins.foldl' (services: ifName: services // { + "wireguard-key-${ifName}" = { + description = "Create key file for wireguard interface '${ifName}'"; + requiredBy = [ "systemd-networkd.service" ]; + script = '' + #! ${pkgs.runtimeShell} -e + + F=${privateKeyFile ifName} + mkdir -p -m 0700 $(dirname $F) + chown systemd-network:systemd-network $(dirname $F) + rm -f $F + cat >$F <