2 with import ./parse.nix { inherit lib; };
7 let abis = lib.mapAttrs (_: abi: builtins.removeAttrs abi [ "assertions" ]) abis_; in
10 # these patterns are to be matched against {host,build,target}Platform.parsed
12 # The patterns below are lists in sum-of-products form.
14 # Each attribute is list of product conditions; non-list values are treated
15 # as a singleton list. If *any* product condition in the list matches then
16 # the predicate matches. Each product condition is tested by
17 # `lib.attrsets.matchAttrs`, which requires a match on *all* attributes of
20 isi686 = { cpu = cpuTypes.i686; };
21 isx86_32 = { cpu = { family = "x86"; bits = 32; }; };
22 isx86_64 = { cpu = { family = "x86"; bits = 64; }; };
23 isPower = { cpu = { family = "power"; }; };
24 isPower64 = { cpu = { family = "power"; bits = 64; }; };
25 # This ABI is the default in NixOS PowerPC64 BE, but not on mainline GCC,
26 # so it sometimes causes issues in certain packages that makes the wrong
27 # assumption on the used ABI.
29 { abi = { abi = "elfv2"; }; }
30 { abi = { name = "musl"; }; cpu = { family = "power"; bits = 64; }; }
32 isx86 = { cpu = { family = "x86"; }; };
33 isAarch32 = { cpu = { family = "arm"; bits = 32; }; };
34 isArmv7 = map ({ arch, ... }: { cpu = { inherit arch; }; })
35 (lib.filter (cpu: lib.hasPrefix "armv7" cpu.arch or "")
36 (lib.attrValues cpuTypes));
37 isAarch64 = { cpu = { family = "arm"; bits = 64; }; };
38 isAarch = { cpu = { family = "arm"; }; };
39 isMicroBlaze = { cpu = { family = "microblaze"; }; };
40 isMips = { cpu = { family = "mips"; }; };
41 isMips32 = { cpu = { family = "mips"; bits = 32; }; };
42 isMips64 = { cpu = { family = "mips"; bits = 64; }; };
43 isMips64n32 = { cpu = { family = "mips"; bits = 64; }; abi = { abi = "n32"; }; };
44 isMips64n64 = { cpu = { family = "mips"; bits = 64; }; abi = { abi = "64"; }; };
45 isMmix = { cpu = { family = "mmix"; }; };
46 isRiscV = { cpu = { family = "riscv"; }; };
47 isRiscV32 = { cpu = { family = "riscv"; bits = 32; }; };
48 isRiscV64 = { cpu = { family = "riscv"; bits = 64; }; };
49 isRx = { cpu = { family = "rx"; }; };
50 isSparc = { cpu = { family = "sparc"; }; };
51 isSparc64 = { cpu = { family = "sparc"; bits = 64; }; };
52 isWasm = { cpu = { family = "wasm"; }; };
53 isMsp430 = { cpu = { family = "msp430"; }; };
54 isVc4 = { cpu = { family = "vc4"; }; };
55 isAvr = { cpu = { family = "avr"; }; };
56 isAlpha = { cpu = { family = "alpha"; }; };
57 isOr1k = { cpu = { family = "or1k"; }; };
58 isM68k = { cpu = { family = "m68k"; }; };
59 isS390 = { cpu = { family = "s390"; }; };
60 isS390x = { cpu = { family = "s390"; bits = 64; }; };
61 isLoongArch64 = { cpu = { family = "loongarch"; bits = 64; }; };
62 isJavaScript = { cpu = cpuTypes.javascript; };
64 is32bit = { cpu = { bits = 32; }; };
65 is64bit = { cpu = { bits = 64; }; };
66 isILP32 = [ { cpu = { family = "wasm"; bits = 32; }; } ] ++
67 map (a: { abi = { abi = a; }; }) [ "n32" "ilp32" "x32" ];
68 isBigEndian = { cpu = { significantByte = significantBytes.bigEndian; }; };
69 isLittleEndian = { cpu = { significantByte = significantBytes.littleEndian; }; };
71 isBSD = { kernel = { families = { inherit (kernelFamilies) bsd; }; }; };
72 isDarwin = { kernel = { families = { inherit (kernelFamilies) darwin; }; }; };
73 isUnix = [ isBSD isDarwin isLinux isSunOS isCygwin isRedox ];
75 isMacOS = { kernel = kernels.macos; };
76 isiOS = { kernel = kernels.ios; };
77 isLinux = { kernel = kernels.linux; };
78 isSunOS = { kernel = kernels.solaris; };
79 isFreeBSD = { kernel = { name = "freebsd"; }; };
80 isNetBSD = { kernel = kernels.netbsd; };
81 isOpenBSD = { kernel = kernels.openbsd; };
82 isWindows = { kernel = kernels.windows; };
83 isCygwin = { kernel = kernels.windows; abi = abis.cygnus; };
84 isMinGW = { kernel = kernels.windows; abi = abis.gnu; };
85 isWasi = { kernel = kernels.wasi; };
86 isRedox = { kernel = kernels.redox; };
87 isGhcjs = { kernel = kernels.ghcjs; };
88 isGenode = { kernel = kernels.genode; };
89 isNone = { kernel = kernels.none; };
91 isAndroid = [ { abi = abis.android; } { abi = abis.androideabi; } ];
92 isGnu = with abis; map (a: { abi = a; }) [ gnuabi64 gnuabin32 gnu gnueabi gnueabihf gnuabielfv1 gnuabielfv2 ];
93 isMusl = with abis; map (a: { abi = a; }) [ musl musleabi musleabihf muslabin32 muslabi64 ];
94 isUClibc = with abis; map (a: { abi = a; }) [ uclibc uclibceabi uclibceabihf ];
97 { cpu = { family = "arm"; version = "6"; }; }
98 { cpu = { family = "arm"; version = "7"; }; }
99 { cpu = { family = "arm"; version = "8"; }; }
100 { cpu = { family = "riscv"; }; }
101 { cpu = { family = "x86"; }; }
104 isElf = { kernel.execFormat = execFormats.elf; };
105 isMacho = { kernel.execFormat = execFormats.macho; };
108 # given two patterns, return a pattern which is their logical AND.
109 # Since a pattern is a list-of-disjuncts, this needs to
110 patternLogicalAnd = pat1_: pat2_:
112 # patterns can be either a list or a (bare) singleton; turn
113 # them into singletons for uniform handling
114 pat1 = lib.toList pat1_;
115 pat2 = lib.toList pat2_;
117 lib.concatMap (attr1:
119 lib.recursiveUpdateUntil
120 (path: subattr1: subattr2:
121 if (builtins.intersectAttrs subattr1 subattr2) == {} || subattr1 == subattr2
124 pattern conflict at path ${toString path}:
125 ${builtins.toJSON subattr1}
126 ${builtins.toJSON subattr2}
134 matchAnyAttrs = patterns:
135 if builtins.isList patterns then attrs: any (pattern: matchAttrs pattern attrs) patterns
136 else matchAttrs patterns;
138 predicates = mapAttrs (_: matchAnyAttrs) patterns;
140 # these patterns are to be matched against the entire
141 # {host,build,target}Platform structure; they include a `parsed={}` marker so
142 # that `lib.meta.availableOn` can distinguish them from the patterns which
143 # apply only to the `parsed` field.
145 platformPatterns = mapAttrs (_: p: { parsed = {}; } // p) {
146 isStatic = { isStatic = true; };