From 642d97cb52c4323cbba2d9bb4070bc09312c3dae Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Fri, 7 Apr 2023 13:47:40 +0200 Subject: [PATCH] wireguard/home: Add basic overview page It is very basic and not pretty, but it is a base that can be extended. --- modules/wireguard/home.nix | 40 +++++++++++++++++++++++++++- modules/wireguard/home/index.html.j2 | 22 +++++++++++++++ modules/wireguard/home/style.css | 10 +++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 modules/wireguard/home/index.html.j2 create mode 100644 modules/wireguard/home/style.css diff --git a/modules/wireguard/home.nix b/modules/wireguard/home.nix index 35aed52..f3920cf 100644 --- a/modules/wireguard/home.nix +++ b/modules/wireguard/home.nix @@ -1,4 +1,4 @@ -{ lib, config, pkgs, ... }: +{ lib, config, machines, pkgs, ... }: let serverHostName = "vueko"; peers = { @@ -113,8 +113,46 @@ in $TTL 3600 @ IN SOA ${serverHostName}.sbruder.de. hostmaster.sbruder.de. ${toString serial} 28800 3600 604800 3600 @ IN NS ${serverHostName}.sbruder.de. + @ IN A ${peers.${serverHostName}.address} '' + peerRecords); }; }; + + services.nginx = lib.mkIf enableServer { + virtualHosts."vpn.sbruder.de" = { + root = + let + templateData = { + machines = lib.mapAttrs + (machine: { config, ... }: { + syncthing = if config.services.syncthing.enable then 8384 else null; + }) + machines; + }; + in + pkgs.stdenv.mkDerivation { + name = "vpn-home"; + + src = ./home; + + nativeBuildInputs = with pkgs; [ j2cli ]; + + buildPhase = '' + runHook preBuild + j2 -f json -o index.html index.html.j2 - << EOF + ${builtins.toJSON templateData} + EOF + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + install -D index.html $out/index.html + install -D style.css $out/style.css + runHook postInstall + ''; + }; + }; + }; }; } diff --git a/modules/wireguard/home/index.html.j2 b/modules/wireguard/home/index.html.j2 new file mode 100644 index 0000000..fdab2ee --- /dev/null +++ b/modules/wireguard/home/index.html.j2 @@ -0,0 +1,22 @@ + + + + + + VPN + + + +
+

VPN

+

Machines

+ {%- for machine, config in machines.items() %} + {%- set base_url = "http://" ~ machine ~ ".vpn.sbruder.de" %} +

{{ machine }}

+ + {%- endfor %} +
+ + diff --git a/modules/wireguard/home/style.css b/modules/wireguard/home/style.css new file mode 100644 index 0000000..5d1e675 --- /dev/null +++ b/modules/wireguard/home/style.css @@ -0,0 +1,10 @@ +body { + font-family: "PT Sans", "Helvetica", "Helvetica Neue", "Roboto", "Arimo", "Arial", sans-serif; + margin: 0px; +} + +.container { + max-width: 500px; + margin: 0 auto; + padding: 0 1rem; +}