-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
profiles.nix
57 lines (53 loc) · 1.56 KB
/
profiles.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{ pkgs ? import <nixpkgs> {}
# OpenWRT release
, release ? import ./latest-release.nix
}:
let
inherit (pkgs) lib;
in rec {
hashes = import ./hashes/${release}.nix;
allProfiles =
if release == "snapshot"
then
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.targets
else
import ./cached-profiles/${release}.nix;
# filters hardware profiles from all boards.json files
identifyProfiles = 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);
identifyProfile = profile:
let
matches = identifyProfiles profile;
in
if builtins.length matches == 1
then builtins.head matches
else if matches == []
then throw "No match for OpenWRT profile ${profile}"
else builtins.trace ''
${builtins.length matches} matches for OpenWRT profile ${profile}
${lib.concatMapStrings ({ target, variant }: ''
- ${target}/${variant}
'') matches}
Using first.
'' (builtins.head matches);
}