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