2024-05-11 23:48:06 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
secrets = import ./extneder-secrets.nix;
|
|
|
|
rsecrets = import ./rotuer-secrets.nix;
|
2024-05-14 13:52:50 +02:00
|
|
|
lns = "l2tp.aaisp.net.uk";
|
2024-05-11 23:48:06 +02:00
|
|
|
inherit (pkgs.liminix.services) oneshot longrun bundle target;
|
|
|
|
inherit (pkgs.pseudofile) dir symlink;
|
|
|
|
inherit (pkgs) writeText dropbear ifwait serviceFns;
|
|
|
|
svc = config.system.service;
|
|
|
|
in rec {
|
|
|
|
boot = {
|
|
|
|
tftp = {
|
|
|
|
serverip = "10.0.0.1";
|
|
|
|
ipaddr = "10.0.0.8";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
imports = [
|
2024-05-14 19:07:33 +02:00
|
|
|
../modules/cdc-ncm
|
2024-05-11 23:48:06 +02:00
|
|
|
../modules/network
|
|
|
|
../modules/vlan
|
|
|
|
../modules/ssh
|
|
|
|
../modules/usb.nix
|
|
|
|
../modules/watchdog
|
|
|
|
../modules/mount
|
|
|
|
../modules/ppp
|
2024-07-30 23:37:43 +02:00
|
|
|
../modules/round-robin
|
|
|
|
../modules/health-check
|
|
|
|
../modules/profiles/gateway.nix
|
2024-05-11 23:48:06 +02:00
|
|
|
];
|
|
|
|
hostname = "thing";
|
|
|
|
|
2024-05-15 18:36:16 +02:00
|
|
|
services.wwan = svc.wwan.build {
|
|
|
|
apn = "data.uk";
|
|
|
|
username = "user";
|
|
|
|
password = "one2one";
|
|
|
|
authType = "chap";
|
|
|
|
};
|
|
|
|
|
2024-07-30 23:37:43 +02:00
|
|
|
profile.gateway = {
|
|
|
|
lan = {
|
|
|
|
interfaces = with config.hardware.networkInterfaces;
|
|
|
|
[
|
|
|
|
# EDIT: these are the interfaces exposed by the gl.inet gl-ar750:
|
|
|
|
# if your device has more or differently named lan interfaces,
|
|
|
|
# specify them here
|
|
|
|
wlan wlan5
|
|
|
|
lan
|
|
|
|
];
|
|
|
|
inherit (rsecrets.lan) prefix;
|
|
|
|
address = {
|
|
|
|
family = "inet"; address ="${rsecrets.lan.prefix}.1"; prefixLength = 24;
|
|
|
|
};
|
|
|
|
dhcp = {
|
|
|
|
start = 10;
|
|
|
|
end = 240;
|
|
|
|
hosts = { } // lib.optionalAttrs (builtins.pathExists ./static-leases.nix) (import ./static-leases.nix);
|
|
|
|
localDomain = "lan";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
wan = {
|
|
|
|
interface = let
|
|
|
|
pppoe = svc.pppoe.build {
|
|
|
|
interface = config.hardware.networkInterfaces.wan;
|
|
|
|
debug = true;
|
|
|
|
username = rsecrets.l2tp.name;
|
|
|
|
password = rsecrets.l2tp.password;
|
|
|
|
};
|
|
|
|
|
|
|
|
l2tp =
|
|
|
|
let
|
|
|
|
check-address = oneshot rec {
|
|
|
|
name = "check-lns-address";
|
|
|
|
up = "grep -Fx ${lns.address} $(output_path ${services.lns-address} addresses)";
|
|
|
|
dependencies = [ services.lns-address ];
|
|
|
|
};
|
|
|
|
route = svc.network.route.build {
|
|
|
|
via = "$(output ${services.bootstrap-dhcpc} router)";
|
|
|
|
target = lns.address;
|
|
|
|
dependencies = [services.bootstrap-dhcpc check-address];
|
|
|
|
};
|
|
|
|
l2tpd= svc.l2tp.build {
|
|
|
|
lns = lns.address;
|
|
|
|
ppp-options = [
|
|
|
|
"debug" "+ipv6" "noauth"
|
|
|
|
"name" rsecrets.l2tp.name
|
|
|
|
"password" rsecrets.l2tp.password
|
|
|
|
];
|
|
|
|
dependencies = [config.services.lns-address route check-address];
|
|
|
|
};
|
|
|
|
in
|
|
|
|
svc.health-check.build {
|
|
|
|
service = l2tpd;
|
|
|
|
threshold = 3;
|
|
|
|
interval = 2;
|
|
|
|
healthCheck = pkgs.writeAshScript "ping-check" {} "ping 1.1.1.1";
|
|
|
|
};
|
|
|
|
in svc.round-robin.build {
|
|
|
|
name = "wan";
|
|
|
|
services = [
|
|
|
|
pppoe
|
|
|
|
l2tp
|
|
|
|
];
|
|
|
|
};
|
|
|
|
dhcp6.enable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
wireless.networks = {
|
|
|
|
"${rsecrets.ssid}" = {
|
|
|
|
interface = config.hardware.networkInterfaces.wlan;
|
|
|
|
hw_mode = "g";
|
|
|
|
channel = "6";
|
|
|
|
ieee80211n = 1;
|
|
|
|
} // wirelessConfig;
|
|
|
|
"${rsecrets.ssid}5" = rec {
|
|
|
|
interface = config.hardware.networkInterfaces.wlan5;
|
|
|
|
hw_mode = "a";
|
|
|
|
channel = 36;
|
|
|
|
ht_capab = "[HT40+]";
|
|
|
|
vht_oper_chwidth = 1;
|
|
|
|
vht_oper_centr_freq_seg0_idx = channel + 6;
|
|
|
|
ieee80211n = 1;
|
|
|
|
ieee80211ac = 1;
|
|
|
|
} // wirelessConfig;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.bootstrap-dhcpc = svc.network.dhcp.client.build {
|
2024-05-14 23:19:34 +02:00
|
|
|
interface = config.services.wwan;
|
|
|
|
dependencies = [ config.services.hostname ];
|
|
|
|
};
|
2024-05-11 23:48:06 +02:00
|
|
|
|
|
|
|
services.sshd = svc.ssh.build { };
|
|
|
|
|
|
|
|
services.resolvconf = oneshot rec {
|
|
|
|
dependencies = [ services.dhcpc ];
|
|
|
|
name = "resolvconf";
|
|
|
|
up = ''
|
|
|
|
. ${serviceFns}
|
|
|
|
( in_outputs ${name}
|
|
|
|
for i in $(output ${services.dhcpc} dns); do
|
|
|
|
echo "nameserver $i" > resolv.conf
|
|
|
|
done
|
|
|
|
)
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
filesystem = dir {
|
|
|
|
etc = dir {
|
|
|
|
"resolv.conf" = symlink "${services.resolvconf}/.outputs/resolv.conf";
|
|
|
|
};
|
|
|
|
srv = dir {};
|
|
|
|
};
|
|
|
|
|
2024-05-14 13:52:50 +02:00
|
|
|
services.lnsroute = svc.network.route.build {
|
|
|
|
via = "$(output ${services.dhcpc} router)";
|
|
|
|
target = lns;
|
|
|
|
dependencies = [services.dhcpc];
|
|
|
|
};
|
|
|
|
|
2024-05-11 23:48:06 +02:00
|
|
|
services.l2tp = svc.l2tp.build {
|
2024-05-14 13:52:50 +02:00
|
|
|
inherit lns;
|
2024-05-11 23:48:06 +02:00
|
|
|
ppp-options = [
|
|
|
|
"debug" "+ipv6" "noauth"
|
|
|
|
"name" rsecrets.l2tp.name
|
|
|
|
"password" rsecrets.l2tp.password
|
|
|
|
];
|
2024-05-14 13:52:50 +02:00
|
|
|
dependencies = [ services.lnsroute ];
|
2024-05-11 23:48:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
services.defaultroute4 = svc.network.route.build {
|
2024-05-14 13:52:50 +02:00
|
|
|
via = "$(output ${services.l2tp} router)";
|
2024-05-11 23:48:06 +02:00
|
|
|
target = "default";
|
2024-05-14 13:52:50 +02:00
|
|
|
dependencies = [services.l2tp];
|
2024-05-11 23:48:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
users.root = {
|
|
|
|
passwd = lib.mkForce secrets.root.passwd;
|
|
|
|
openssh.authorizedKeys.keys = secrets.root.keys;
|
|
|
|
};
|
|
|
|
}
|