2022-09-25 12:54:31 +02:00
|
|
|
{
|
|
|
|
liminix
|
|
|
|
, lib
|
|
|
|
, ppp
|
|
|
|
, pppoe
|
2022-09-25 22:12:23 +02:00
|
|
|
, writeAshScript
|
2023-02-25 23:53:06 +01:00
|
|
|
, serviceFns
|
2022-09-25 12:54:31 +02:00
|
|
|
} :
|
|
|
|
let
|
|
|
|
inherit (liminix.services) longrun;
|
2023-07-14 17:53:36 +02:00
|
|
|
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;
|
2022-09-25 12:54:31 +02:00
|
|
|
in
|
2023-07-14 17:53:36 +02:00
|
|
|
params:
|
2022-09-25 22:12:23 +02:00
|
|
|
let
|
2023-07-14 17:53:36 +02:00
|
|
|
inherit (typeChecked t' params) ppp-options interface;
|
2022-09-25 22:12:23 +02:00
|
|
|
name = "${interface.device}.pppoe";
|
|
|
|
ip-up = writeAshScript "ip-up" {} ''
|
2023-02-25 23:53:06 +01:00
|
|
|
. ${serviceFns}
|
2023-03-04 00:06:18 +01:00
|
|
|
(in_outputs ${name}
|
2023-02-25 23:53:06 +01:00
|
|
|
echo $1 > ifname
|
|
|
|
echo $2 > tty
|
|
|
|
echo $3 > speed
|
|
|
|
echo $4 > address
|
|
|
|
echo $5 > peer-address
|
|
|
|
echo $DNS1 > ns1
|
|
|
|
echo $DNS2 > ns2
|
2022-09-25 22:12:23 +02:00
|
|
|
)
|
|
|
|
echo >/proc/self/fd/10
|
|
|
|
'';
|
2023-05-25 00:01:50 +02:00
|
|
|
ip6-up = writeAshScript "ip6-up" {} ''
|
|
|
|
. ${serviceFns}
|
|
|
|
(in_outputs ${name}
|
|
|
|
echo $4 > ipv6-address
|
|
|
|
echo $5 > ipv6-peer-address
|
|
|
|
)
|
|
|
|
echo >/proc/self/fd/10
|
|
|
|
'';
|
2022-09-25 22:12:23 +02:00
|
|
|
ppp-options' = ppp-options ++ [
|
|
|
|
"ip-up-script" ip-up
|
2023-05-25 00:01:50 +02:00
|
|
|
"ipv6-up-script" ip6-up
|
2022-09-25 22:12:23 +02:00
|
|
|
"ipparam" name
|
|
|
|
"nodetach"
|
2023-02-25 21:31:41 +01:00
|
|
|
"usepeerdns"
|
2022-09-27 23:57:06 +02:00
|
|
|
"logfd" "2"
|
2022-09-25 22:12:23 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
in
|
|
|
|
longrun {
|
|
|
|
inherit name;
|
|
|
|
run = "${ppp}/bin/pppd pty '${pppoe}/bin/pppoe -I ${interface.device}' ${lib.concatStringsSep " " ppp-options'}" ;
|
|
|
|
notification-fd = 10;
|
|
|
|
dependencies = [ interface ];
|
2022-09-25 12:54:31 +02:00
|
|
|
}
|