From 69e6eb5a898234dad82176b3c69bbc491ac5930d Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Fri, 14 Jul 2023 16:53:36 +0100 Subject: [PATCH] accept attr args to pppoe service, and typecheck them We use (abuse, arguably) the nixos module system for typechecking. Un the plus side, it gives us documentation of the options and their expected types. On the downside, the error message doesn't tell us the file in which the error was encountered. (This is subject to change, if I can find a better way) --- examples/rotuer.nix | 3 ++- modules/ppp.nix | 2 +- pkgs/liminix-tools/networking/pppoe.nix | 23 ++++++++++++++++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/examples/rotuer.nix b/examples/rotuer.nix index 06d5fefe..3be133e6 100644 --- a/examples/rotuer.nix +++ b/examples/rotuer.nix @@ -191,7 +191,8 @@ in rec { services.wan = let iface = config.hardware.networkInterfaces.wan; - in config.system.service.pppoe iface { + in config.system.service.pppoe { + interface = iface; ppp-options = [ "debug" "+ipv6" "noauth" "name" secrets.l2tp.name diff --git a/modules/ppp.nix b/modules/ppp.nix index 08519e4c..b1b19ea7 100644 --- a/modules/ppp.nix +++ b/modules/ppp.nix @@ -6,7 +6,7 @@ let in { options = { system.service.pppoe = mkOption { - type = types.functionTo (types.functionTo types.package); + type = types.functionTo types.package; }; }; config = { diff --git a/pkgs/liminix-tools/networking/pppoe.nix b/pkgs/liminix-tools/networking/pppoe.nix index 1fbf7762..238ad17e 100644 --- a/pkgs/liminix-tools/networking/pppoe.nix +++ b/pkgs/liminix-tools/networking/pppoe.nix @@ -8,13 +8,26 @@ } : let inherit (liminix.services) longrun; + inherit (lib) + mergeDefinitions + mkEnableOption mkOption isType types isDerivation hasAttr; + t = { + interface = mkOption { + type = types.package; # actually a service + description = "ethernet interface to run PPPoE over"; + }; + ppp-options = mkOption { + type = types.listOf types.str; + }; + }; + t' = types.submodule { options = t; }; + typeChecked = type: value: + let defs = [{ file = "pppoe.nix"; inherit value; }]; + in (lib.mergeDefinitions [ ] type defs).mergedValue; in -interface: { - synchronous ? false -, ppp-options ? [] -, ... -} @ args: +params: let + inherit (typeChecked t' params) ppp-options interface; name = "${interface.device}.pppoe"; ip-up = writeAshScript "ip-up" {} '' . ${serviceFns}