pkgs/openwrt-images: refactor, embed hostName in extraImageName

This commit is contained in:
Astro 2022-04-30 02:55:01 +02:00
parent 7a00fd74cf
commit 4b09601419

View File

@ -77,12 +77,35 @@ let
'') (builtins.attrValues rootfs-packages)}
'';
openwrt-images =
openwrt-images = builtins.foldl' (images: hostName:
let
profiles = openwrt-imagebuilder.lib.profiles { inherit pkgs; };
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 = {
base = "0xklqsk6d5d6bai0ry2hzfjr4sycf6241ihv8v1lmmf9r7d47cr1";
packages = "05g048saibh304ndnlczyq92b1c67c3cqvbhdamw1xqbsp6jzifp";
};
}
else null;
build = args:
openwrt-imagebuilder.lib.build (args // {
extraImageName = "zw";
extraImageName = "zw-${hostName}";
packages = [
# remove unused default .ipk
"-dnsmasq" "-ppp" "-ppp-mod-pppoe" "-odhcp6c" "-odhcpd-ipv6only"
@ -96,57 +119,32 @@ let
# TODO: files
});
in
builtins.foldl' (images: hostName:
let
inherit (config.site.hosts.${hostName}) model;
matches = profiles.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 = {
base = "0xklqsk6d5d6bai0ry2hzfjr4sycf6241ihv8v1lmmf9r7d47cr1";
packages = "05g048saibh304ndnlczyq92b1c67c3cqvbhdamw1xqbsp6jzifp";
};
}
else null;
in
if matches == [] && fallbackProfile != null
then images // {
"${hostName}-image" = build fallbackProfile;
}
else if matches == []
then builtins.trace "${hostName} (${model}) not supported by OpenWRT"
images
else if builtins.length matches == 1
then
images // {
"${hostName}-image" = build (
builtins.elemAt matches 0
);
}
else builtins.trace "${hostName} (${model}) has multiple models!"
images // {
"${hostName}-image" = build (
builtins.elemAt matches 0
);
}
) {} (
builtins.attrNames (
nixpkgs.lib.filterAttrs (_: { role, ... }: role == "ap")
config.site.hosts
)
);
if matches == [] && fallbackProfile != null
then images // {
"${hostName}-image" = build fallbackProfile;
}
else if matches == []
then builtins.trace "${hostName} (${model}) not supported by OpenWRT"
images
else if builtins.length matches == 1
then
images // {
"${hostName}-image" = build (
builtins.elemAt matches 0
);
}
else builtins.trace "${hostName} (${model}) has multiple models!"
images // {
"${hostName}-image" = build (
builtins.elemAt matches 0
);
}
) {} (
builtins.attrNames (
nixpkgs.lib.filterAttrs (_: { role, ... }: role == "ap")
config.site.hosts
)
);
device-templates = import ./device-templates.nix {
inherit self nixpkgs system;