From 7f9cae9d5cf5560ff701fa075a8bc54df74755b6 Mon Sep 17 00:00:00 2001
From: Daniel Barlow <dan@telent.net>
Date: Tue, 16 Jul 2024 22:10:09 +0100
Subject: [PATCH] generalise profile.gateway.wan so not just pppoe

---
 NEWS                         | 12 ++++++++++++
 examples/rotuer.nix          | 14 +++++++++++---
 modules/profiles/gateway.nix |  6 +-----
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/NEWS b/NEWS
index 22d0ebad..d07f0fca 100644
--- a/NEWS
+++ b/NEWS
@@ -103,3 +103,15 @@ a bit more useful :-)
       };
     })
   ];
+
+2024-07-16
+
+* structured parameters are available for the pppoe service
+
+* The "wan" configuration in modules/profiles/gateway.nix has changed:
+instead of passing options that are used to create a pppoe interface,
+callers should create a (pppoe or other) interface and pass that as
+the value of profile.gateway.wan. For the pppoe case this is now only
+very slightly more verbose, and it allows using the gateway profile
+with other kinds of upstream.
+
diff --git a/examples/rotuer.nix b/examples/rotuer.nix
index e7eb38de..1d2a726c 100644
--- a/examples/rotuer.nix
+++ b/examples/rotuer.nix
@@ -53,9 +53,17 @@ in rec {
       };
     };
     wan = {
-      interface = config.hardware.networkInterfaces.wan;
-      username = secrets.l2tp.name;
-      password = secrets.l2tp.password;
+      # wan interface depends on your upstream - could be dhcp, static
+      # ethernet, a pppoe, ppp over serial, a complicated bonded
+      # failover ... who knows what else?
+      interface = svc.pppoe.build {
+        interface = config.hardware.networkInterfaces.wan;
+        username = secrets.l2tp.name;
+        password = secrets.l2tp.password;
+      };
+      # once the wan has ipv4 connnectivity, should we run dhcp6
+      # client to potentially get an address range ("prefix
+      # delegation")
       dhcp6.enable = true;
     };
     firewall = {
diff --git a/modules/profiles/gateway.nix b/modules/profiles/gateway.nix
index 762b8c93..3938bb2e 100644
--- a/modules/profiles/gateway.nix
+++ b/modules/profiles/gateway.nix
@@ -52,8 +52,6 @@ in {
 
     wan = {
       interface = mkOption { type = liminix.lib.types.interface; };
-      username = mkOption { type = types.str; };
-      password =  mkOption { type = types.str; };
       dhcp6.enable = mkOption { type = types.bool; };
     };
 
@@ -86,9 +84,7 @@ in {
       members = cfg.lan.interfaces;
     };
 
-    services.wan = svc.pppoe.build {
-      inherit (cfg.wan) interface username password;
-    };
+    services.wan = cfg.wan.interface;
 
     services.packet_forwarding = svc.network.forward.build { };