diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2018-03-19 22:14:45 -0400 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2018-03-20 12:35:20 -0400 |
commit | 175d4ab1db65088c008e667f0423efbf325c179f (patch) | |
tree | 970a6e46031b089f2612205d9a183049f1cccc0c /lib/systems/inspect.nix | |
parent | ec2aff0be670646bd5dbb3da7ae6f59afd36e215 (diff) |
lib: Make platform predicates greppable
Should have commited on here and on merged master to begin with, but I
didn't, so instead I cherry-pick.
(cherry picked from commit 88c04a8b6b6714a61c8a28ec8bbd5ecf580ed2c7)
Diffstat (limited to 'lib/systems/inspect.nix')
-rw-r--r-- | lib/systems/inspect.nix | 80 |
1 files changed, 39 insertions, 41 deletions
diff --git a/lib/systems/inspect.nix b/lib/systems/inspect.nix index ab220af46e30..a7bd17f68a45 100644 --- a/lib/systems/inspect.nix +++ b/lib/systems/inspect.nix @@ -5,51 +5,49 @@ with lib.lists; rec { patterns = rec { - i686 = { cpu = cpuTypes.i686; }; - x86_64 = { cpu = cpuTypes.x86_64; }; - PowerPC = { cpu = cpuTypes.powerpc; }; - x86 = { cpu = { family = "x86"; }; }; - Arm = { cpu = { family = "arm"; }; }; - Aarch64 = { cpu = { family = "aarch64"; }; }; - Mips = { cpu = { family = "mips"; }; }; - RiscV = { cpu = { family = "riscv"; }; }; - Wasm = { cpu = { family = "wasm"; }; }; - - "32bit" = { cpu = { bits = 32; }; }; - "64bit" = { cpu = { bits = 64; }; }; - BigEndian = { cpu = { significantByte = significantBytes.bigEndian; }; }; - LittleEndian = { cpu = { significantByte = significantBytes.littleEndian; }; }; - - BSD = { kernel = { families = { inherit (kernelFamilies) bsd; }; }; }; - Unix = [ BSD Darwin Linux SunOS Hurd Cygwin ]; - - Darwin = { kernel = kernels.darwin; }; - Linux = { kernel = kernels.linux; }; - SunOS = { kernel = kernels.solaris; }; - FreeBSD = { kernel = kernels.freebsd; }; - Hurd = { kernel = kernels.hurd; }; - NetBSD = { kernel = kernels.netbsd; }; - OpenBSD = { kernel = kernels.openbsd; }; - Windows = { kernel = kernels.windows; }; - Cygwin = { kernel = kernels.windows; abi = abis.cygnus; }; - MinGW = { kernel = kernels.windows; abi = abis.gnu; }; - - Android = [ { abi = abis.android; } { abi = abis.androideabi; } ]; - Musl = with abis; map (a: { abi = a; }) [ musl musleabi musleabihf ]; - - Kexecable = map (family: { kernel = kernels.linux; cpu.family = family; }) - [ "x86" "arm" "aarch64" "mips" ]; - Efi = map (family: { cpu.family = family; }) - [ "x86" "arm" "aarch64" ]; - Seccomputable = map (family: { kernel = kernels.linux; cpu.family = family; }) - [ "x86" "arm" "aarch64" "mips" ]; + isi686 = { cpu = cpuTypes.i686; }; + isx86_64 = { cpu = cpuTypes.x86_64; }; + isPowerPC = { cpu = cpuTypes.powerpc; }; + isx86 = { cpu = { family = "x86"; }; }; + isArm = { cpu = { family = "arm"; }; }; + isAarch64 = { cpu = { family = "aarch64"; }; }; + isMips = { cpu = { family = "mips"; }; }; + isRiscV = { cpu = { family = "riscv"; }; }; + isWasm = { cpu = { family = "wasm"; }; }; + + is32bit = { cpu = { bits = 32; }; }; + is64bit = { cpu = { bits = 64; }; }; + isBigEndian = { cpu = { significantByte = significantBytes.bigEndian; }; }; + isLittleEndian = { cpu = { significantByte = significantBytes.littleEndian; }; }; + + isBSD = { kernel = { families = { inherit (kernelFamilies) bsd; }; }; }; + isUnix = [ isBSD isDarwin isLinux isSunOS isHurd isCygwin ]; + + isDarwin = { kernel = kernels.darwin; }; + isLinux = { kernel = kernels.linux; }; + isSunOS = { kernel = kernels.solaris; }; + isFreeBSD = { kernel = kernels.freebsd; }; + isHurd = { kernel = kernels.hurd; }; + isNetBSD = { kernel = kernels.netbsd; }; + isOpenBSD = { kernel = kernels.openbsd; }; + isWindows = { kernel = kernels.windows; }; + isCygwin = { kernel = kernels.windows; abi = abis.cygnus; }; + isMinGW = { kernel = kernels.windows; abi = abis.gnu; }; + + isAndroid = [ { abi = abis.android; } { abi = abis.androideabi; } ]; + isMusl = with abis; map (a: { abi = a; }) [ musl musleabi musleabihf ]; + + isKexecable = map (family: { kernel = kernels.linux; cpu.family = family; }) + [ "x86" "arm" "aarch64" "mips" ]; + isEfi = map (family: { cpu.family = family; }) + [ "x86" "arm" "aarch64" ]; + isSeccomputable = map (family: { kernel = kernels.linux; cpu.family = family; }) + [ "x86" "arm" "aarch64" "mips" ]; }; matchAnyAttrs = patterns: if builtins.isList patterns then attrs: any (pattern: matchAttrs pattern attrs) patterns else matchAttrs patterns; - predicates = mapAttrs' - (name: value: nameValuePair ("is" + name) (matchAnyAttrs value)) - patterns; + predicates = mapAttrs (_: matchAnyAttrs) patterns; } |