profiles: init with allProfiles+identifyProfile
This commit is contained in:
parent
fbf0e8733b
commit
3db95068d2
52
example.nix
52
example.nix
|
@ -1,34 +1,22 @@
|
|||
{ pkgs ? import <nixpkgs> {}
|
||||
}:
|
||||
import ./builder.nix {
|
||||
inherit pkgs;
|
||||
target = "ath79";
|
||||
profile = "ubnt_unifiac-lite";
|
||||
packages = [
|
||||
"tcpdump"
|
||||
"vxlan" "kmod-vxlan"
|
||||
"-ath10k-firmware-qca988x-ct" "ath10k-firmware-qca988x"
|
||||
"-kmod-ath10k-ct" "kmod-ath10k"
|
||||
];
|
||||
files = pkgs.runCommandNoCC "image-files" {} ''
|
||||
mkdir -p $out/etc/uci-defaults
|
||||
cat > $out/etc/uci-defaults/99-custom <<EOF
|
||||
uci -q batch << EOI
|
||||
set network.lan.ipaddr='192.168.178.1'
|
||||
commit network
|
||||
set wireless.@wifi-device[0].disabled='0'
|
||||
set wireless.@wifi-iface[0].ssid='OpenWrt0815'
|
||||
commit wireless
|
||||
add dhcp host
|
||||
set dhcp.@host[-1].name='bellerophon'
|
||||
set dhcp.@host[-1].ip='192.168.2.100'
|
||||
set dhcp.@host[-1].mac='a1:b2:c3:d4:e5:f6'
|
||||
commit dhcp
|
||||
rename firewall.@zone[0]='lan'
|
||||
rename firewall.@zone[1]='wan'
|
||||
rename firewall.@forwarding[0]='lan_wan'
|
||||
commit firewall
|
||||
EOI
|
||||
EOF
|
||||
'';
|
||||
}
|
||||
let
|
||||
profiles = import ./profiles.nix { inherit pkgs; };
|
||||
in
|
||||
import ./builder.nix (
|
||||
builtins.head (profiles.identifyProfile "avm_fritz7412") // {
|
||||
packages = [
|
||||
"tcpdump"
|
||||
"vxlan" "kmod-vxlan"
|
||||
];
|
||||
files = pkgs.runCommandNoCC "image-files" {} ''
|
||||
mkdir -p $out/etc/uci-defaults
|
||||
cat > $out/etc/uci-defaults/99-custom <<EOF
|
||||
uci -q batch << EOI
|
||||
set system.@system[0].hostname='testap'
|
||||
commit
|
||||
EOI
|
||||
EOF
|
||||
'';
|
||||
}
|
||||
)
|
||||
|
|
14
files.nix
14
files.nix
|
@ -99,12 +99,18 @@ let
|
|||
''
|
||||
) feedsFiles;
|
||||
|
||||
arch = (builtins.fromJSON (
|
||||
builtins.readFile (
|
||||
variantFiles."profiles.json"
|
||||
profiles =
|
||||
if variantFiles ? "profiles.json"
|
||||
then builtins.fromJSON (
|
||||
builtins.readFile (
|
||||
variantFiles."profiles.json"
|
||||
)
|
||||
)
|
||||
)).arch_packages;
|
||||
else null;
|
||||
|
||||
arch = profiles.arch_packages;
|
||||
|
||||
in {
|
||||
inherit variantFiles variantPackages feedsFiles feedsPackages;
|
||||
inherit profiles arch;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
openwrt = if args ? openwrt then args.openwrt else openwrt;
|
||||
});
|
||||
|
||||
lib.profiles = import ./profiles.nix;
|
||||
|
||||
# `nix run .#generate-hashes`
|
||||
packages.x86_64-linux.generate-hashes = import ./generate-hashes.nix {
|
||||
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
{ pkgs ? import <nixpkgs> {}
|
||||
# OpenWRT release
|
||||
, release ? "21.02.3"
|
||||
}:
|
||||
with pkgs;
|
||||
let
|
||||
hashes = import ./hashes/${release}.nix;
|
||||
in rec {
|
||||
allProfiles =
|
||||
builtins.mapAttrs (target: variants:
|
||||
lib.filterAttrs (_: profiles:
|
||||
profiles != null
|
||||
) (
|
||||
builtins.mapAttrs (variant: h:
|
||||
(import ./files.nix {
|
||||
inherit pkgs release target variant;
|
||||
inherit (h) sha256 feedsSha256;
|
||||
}).profiles
|
||||
) variants
|
||||
)
|
||||
) hashes;
|
||||
|
||||
# filters hardware profiles from all boards.json files
|
||||
identifyProfile = profile:
|
||||
builtins.concatMap (target:
|
||||
map (variant: {
|
||||
# match return value
|
||||
inherit pkgs release target variant profile;
|
||||
}) (
|
||||
builtins.filter (variant:
|
||||
allProfiles.${target}.${variant}.profiles ? ${profile}
|
||||
) (builtins.attrNames allProfiles.${target})
|
||||
)
|
||||
) (builtins.attrNames allProfiles);
|
||||
}
|
Loading…
Reference in New Issue