at 24.11-pre 7.1 kB view raw
1{ lib }: 2 3let 4 inherit (lib) 5 any 6 attrValues 7 concatMap 8 filter 9 hasPrefix 10 isList 11 mapAttrs 12 matchAttrs 13 recursiveUpdateUntil 14 toList 15 ; 16 17 inherit (lib.strings) toJSON; 18 19 inherit (lib.systems.parse) 20 kernels 21 kernelFamilies 22 significantBytes 23 cpuTypes 24 execFormats 25 ; 26 27 abis = mapAttrs (_: abi: removeAttrs abi [ "assertions" ]) lib.systems.parse.abis; 28in 29 30rec { 31 # these patterns are to be matched against {host,build,target}Platform.parsed 32 patterns = rec { 33 # The patterns below are lists in sum-of-products form. 34 # 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 39 # the product. 40 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. 49 isAbiElfv2 = [ 50 { abi = { abi = "elfv2"; }; } 51 { abi = { name = "musl"; }; cpu = { family = "power"; bits = 64; }; } 52 ]; 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; }; 84 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; }; }; 91 92 isBSD = { kernel = { families = { inherit (kernelFamilies) bsd; }; }; }; 93 isDarwin = { kernel = { families = { inherit (kernelFamilies) darwin; }; }; }; 94 isUnix = [ isBSD isDarwin isLinux isSunOS isCygwin isRedox ]; 95 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; }; 111 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 ]; 116 117 isEfi = [ 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"; }; } 123 ]; 124 125 isElf = { kernel.execFormat = execFormats.elf; }; 126 isMacho = { kernel.execFormat = execFormats.macho; }; 127 }; 128 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_: 132 let 133 # patterns can be either a list or a (bare) singleton; turn 134 # them into singletons for uniform handling 135 pat1 = toList pat1_; 136 pat2 = toList pat2_; 137 in 138 concatMap (attr1: 139 map (attr2: 140 recursiveUpdateUntil 141 (path: subattr1: subattr2: 142 if (builtins.intersectAttrs subattr1 subattr2) == {} || subattr1 == subattr2 143 then true 144 else throw '' 145 pattern conflict at path ${toString path}: 146 ${toJSON subattr1} 147 ${toJSON subattr2} 148 '') 149 attr1 150 attr2 151 ) 152 pat2) 153 pat1; 154 155 matchAnyAttrs = patterns: 156 if isList patterns then attrs: any (pattern: matchAttrs pattern attrs) patterns 157 else matchAttrs patterns; 158 159 predicates = mapAttrs (_: matchAnyAttrs) patterns; 160 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. 165 166 platformPatterns = mapAttrs (_: p: { parsed = {}; } // p) { 167 isStatic = { isStatic = true; }; 168 }; 169}