2022-05-27 01:37:03 +02:00
|
|
|
{ self, nixpkgs, system, openwrt-imagebuilder }:
|
|
|
|
|
|
|
|
let
|
|
|
|
inherit (self.lib) config;
|
|
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
|
|
uciConfig = hostName: import ./uci-config.nix { inherit self pkgs hostName; };
|
2022-06-23 16:58:17 +02:00
|
|
|
|
|
|
|
modelPackages = {
|
2022-06-23 18:08:59 +02:00
|
|
|
"tplink_archer-c7-v2" = [
|
|
|
|
"-kmod-ath10k-ct" "-ath10k-firmware-qca988x-ct"
|
|
|
|
"kmod-ath10k" "ath10k-firmware-qca988x"
|
|
|
|
];
|
2022-06-23 16:58:17 +02:00
|
|
|
"tplink_archer-c7-v5" = [
|
|
|
|
"-kmod-ath10k-ct" "-ath10k-firmware-qca988x-ct"
|
|
|
|
"kmod-ath10k" "ath10k-firmware-qca988x"
|
|
|
|
];
|
2022-06-23 18:08:59 +02:00
|
|
|
"ubnt_unifiac-lite" = [
|
|
|
|
"-kmod-ath10k-ct" "-ath10k-firmware-qca988x-ct"
|
|
|
|
"kmod-ath10k" "ath10k-firmware-qca988x"
|
|
|
|
];
|
2022-09-13 03:18:21 +02:00
|
|
|
"dir-615-d" = [
|
|
|
|
# flash size reasons
|
|
|
|
"-wpad-openssl"
|
|
|
|
"-tcpdump"
|
|
|
|
"wpad-wolfssl"
|
|
|
|
];
|
2022-06-23 16:58:17 +02:00
|
|
|
};
|
2022-06-23 18:08:41 +02:00
|
|
|
in rec {
|
|
|
|
sshScript = hostName:
|
|
|
|
let
|
|
|
|
address = config.site.net.mgmt.hosts4.${hostName};
|
|
|
|
in ''
|
|
|
|
#! ${pkgs.runtimeShell} -e
|
|
|
|
|
|
|
|
ssh root@${address} "cat > /tmp/openwrt-image" < ${buildImage hostName}/openwrt-*-${hostName}-*-sysupgrade.bin
|
2022-06-23 18:14:27 +02:00
|
|
|
ssh root@${address} "sysupgrade -n /tmp/openwrt-image" || true
|
2022-05-27 01:37:03 +02:00
|
|
|
|
2022-06-23 18:08:41 +02:00
|
|
|
# ssh hostkey will have changed after boot
|
|
|
|
ssh-keygen -R ${address}
|
2022-05-27 01:37:03 +02:00
|
|
|
|
2022-06-23 18:08:41 +02:00
|
|
|
/run/wrappers/bin/ping ${address}
|
|
|
|
'';
|
2022-05-27 01:37:03 +02:00
|
|
|
|
|
|
|
buildImage = hostName:
|
|
|
|
let
|
|
|
|
inherit (config.site.hosts.${hostName}) model;
|
|
|
|
matches = (openwrt-imagebuilder.lib.profiles {
|
|
|
|
inherit pkgs;
|
|
|
|
}).identifyProfiles model;
|
|
|
|
fallbackProfile =
|
|
|
|
if model == "dir-615-d"
|
|
|
|
then (openwrt-imagebuilder.lib.profiles {
|
|
|
|
inherit pkgs;
|
|
|
|
release = "19.07.10";
|
|
|
|
}).identifyProfile model
|
|
|
|
else if builtins.match "tl-wr.*" model != null
|
|
|
|
then {
|
|
|
|
release = "18.06.9";
|
|
|
|
packagesArch = "mips_24kc";
|
|
|
|
target = "ar71xx";
|
|
|
|
variant = "tiny";
|
|
|
|
profile = model;
|
|
|
|
sha256 = "109a2557gwmgib7r500qn9ygd8j4r4cv5jl5rpn9vczsm4ilkc1z";
|
|
|
|
feedsSha256 = {
|
2022-09-12 21:00:58 +02:00
|
|
|
base.sha256 = "0xklqsk6d5d6bai0ry2hzfjr4sycf6241ihv8v1lmmf9r7d47cr1";
|
|
|
|
packages.sha256 = "05g048saibh304ndnlczyq92b1c67c3cqvbhdamw1xqbsp6jzifp";
|
2022-05-27 01:37:03 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
else null;
|
|
|
|
build = args:
|
|
|
|
openwrt-imagebuilder.lib.build (args // {
|
|
|
|
extraImageName = "zw-${hostName}";
|
|
|
|
packages = [
|
|
|
|
# remove unused default .ipk
|
2022-09-13 03:18:55 +02:00
|
|
|
"-dnsmasq" "-firewall"
|
|
|
|
"-ppp" "-ppp-mod-pppoe" "-kmod-ppp" "-kmod-pppoe" "-kmod-pppox"
|
|
|
|
"-iptables" "-ip6tables" "-kmod-ipt-offload"
|
|
|
|
"-odhcp6c" "-odhcpd-ipv6only"
|
2022-05-27 01:37:03 +02:00
|
|
|
# debugging
|
|
|
|
"tcpdump"
|
|
|
|
# monitoring
|
|
|
|
"collectd" "collectd-mod-interface" "collectd-mod-load"
|
|
|
|
"collectd-mod-cpu" "collectd-mod-iwinfo" "collectd-mod-network"
|
2022-09-12 21:41:40 +02:00
|
|
|
# wpa3
|
2022-09-13 02:19:02 +02:00
|
|
|
"-wpad-basic-wolfssl" "-wpad-mini"
|
2022-09-12 21:41:40 +02:00
|
|
|
"wpad-openssl"
|
2022-06-23 16:58:17 +02:00
|
|
|
] ++ modelPackages.${model} or [];
|
2022-05-27 01:37:03 +02:00
|
|
|
disabledServices = [ "dnsmasq" "uhttpd" ];
|
|
|
|
files = pkgs.runCommandNoCC "image-files" {} ''
|
|
|
|
mkdir -p $out/etc/uci-defaults
|
|
|
|
cat > $out/etc/uci-defaults/99-zentralwerk <<EOF
|
|
|
|
${uciConfig hostName}
|
|
|
|
EOF
|
|
|
|
'';
|
|
|
|
});
|
|
|
|
in
|
|
|
|
if matches == [] && fallbackProfile != null
|
|
|
|
then build fallbackProfile
|
|
|
|
else if matches == []
|
|
|
|
then builtins.trace "${hostName} (${model}) not supported by OpenWRT"
|
|
|
|
null
|
|
|
|
else if builtins.length matches == 1
|
|
|
|
then build (builtins.elemAt matches 0)
|
|
|
|
else builtins.trace "${hostName} (${model}) has multiple models!" (
|
|
|
|
build (builtins.elemAt matches 0)
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|