lib: Make platform predicates greppable
This commit is contained in:
parent
5bb50fb9f6
commit
88c04a8b6b
|
@ -7,21 +7,21 @@ in rec {
|
||||||
inherit (lib.systems.doubles) all mesaPlatforms;
|
inherit (lib.systems.doubles) all mesaPlatforms;
|
||||||
none = [];
|
none = [];
|
||||||
|
|
||||||
arm = [ patterns.Arm ];
|
arm = [ patterns.isArm ];
|
||||||
aarch64 = [ patterns.Aarch64 ];
|
aarch64 = [ patterns.isAarch64 ];
|
||||||
x86 = [ patterns.x86 ];
|
x86 = [ patterns.isx86 ];
|
||||||
i686 = [ patterns.i686 ];
|
i686 = [ patterns.isi686 ];
|
||||||
x86_64 = [ patterns.x86_64 ];
|
x86_64 = [ patterns.isx86_64 ];
|
||||||
mips = [ patterns.Mips ];
|
mips = [ patterns.isMips ];
|
||||||
|
|
||||||
cygwin = [ patterns.Cygwin ];
|
cygwin = [ patterns.isCygwin ];
|
||||||
darwin = [ patterns.Darwin ];
|
darwin = [ patterns.isDarwin ];
|
||||||
freebsd = [ patterns.FreeBSD ];
|
freebsd = [ patterns.isFreeBSD ];
|
||||||
# Should be better, but MinGW is unclear, and HURD is bit-rotted.
|
# Should be better, but MinGW is unclear, and HURD is bit-rotted.
|
||||||
gnu = [ { kernel = parse.kernels.linux; abi = parse.abis.gnu; } ];
|
gnu = [ { kernel = parse.kernels.linux; abi = parse.abis.gnu; } ];
|
||||||
illumos = [ patterns.SunOS ];
|
illumos = [ patterns.isSunOS ];
|
||||||
linux = [ patterns.Linux ];
|
linux = [ patterns.isLinux ];
|
||||||
netbsd = [ patterns.NetBSD ];
|
netbsd = [ patterns.isNetBSD ];
|
||||||
openbsd = [ patterns.OpenBSD ];
|
openbsd = [ patterns.isOpenBSD ];
|
||||||
unix = patterns.Unix; # Actually a list
|
unix = patterns.isUnix; # Actually a list
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,53 +5,51 @@ with lib.lists;
|
||||||
|
|
||||||
rec {
|
rec {
|
||||||
patterns = rec {
|
patterns = rec {
|
||||||
i686 = { cpu = cpuTypes.i686; };
|
isi686 = { cpu = cpuTypes.i686; };
|
||||||
x86_64 = { cpu = cpuTypes.x86_64; };
|
isx86_64 = { cpu = cpuTypes.x86_64; };
|
||||||
PowerPC = { cpu = cpuTypes.powerpc; };
|
isPowerPC = { cpu = cpuTypes.powerpc; };
|
||||||
x86 = { cpu = { family = "x86"; }; };
|
isx86 = { cpu = { family = "x86"; }; };
|
||||||
Arm = { cpu = { family = "arm"; }; };
|
isArm = { cpu = { family = "arm"; }; };
|
||||||
Aarch64 = { cpu = { family = "aarch64"; }; };
|
isAarch64 = { cpu = { family = "aarch64"; }; };
|
||||||
Mips = { cpu = { family = "mips"; }; };
|
isMips = { cpu = { family = "mips"; }; };
|
||||||
RiscV = { cpu = { family = "riscv"; }; };
|
isRiscV = { cpu = { family = "riscv"; }; };
|
||||||
Wasm = { cpu = { family = "wasm"; }; };
|
isWasm = { cpu = { family = "wasm"; }; };
|
||||||
|
|
||||||
"32bit" = { cpu = { bits = 32; }; };
|
is32bit = { cpu = { bits = 32; }; };
|
||||||
"64bit" = { cpu = { bits = 64; }; };
|
is64bit = { cpu = { bits = 64; }; };
|
||||||
BigEndian = { cpu = { significantByte = significantBytes.bigEndian; }; };
|
isBigEndian = { cpu = { significantByte = significantBytes.bigEndian; }; };
|
||||||
LittleEndian = { cpu = { significantByte = significantBytes.littleEndian; }; };
|
isLittleEndian = { cpu = { significantByte = significantBytes.littleEndian; }; };
|
||||||
|
|
||||||
BSD = { kernel = { families = { inherit (kernelFamilies) bsd; }; }; };
|
isBSD = { kernel = { families = { inherit (kernelFamilies) bsd; }; }; };
|
||||||
Darwin = { kernel = { families = { inherit (kernelFamilies) darwin; }; }; };
|
isDarwin = { kernel = { families = { inherit (kernelFamilies) darwin; }; }; };
|
||||||
Unix = [ BSD Darwin Linux SunOS Hurd Cygwin ];
|
isUnix = [ isBSD isDarwin isLinux isSunOS isHurd isCygwin ];
|
||||||
|
|
||||||
MacOS = { kernel = kernels.macos; };
|
isMacOS = { kernel = kernels.macos; };
|
||||||
iOS = { kernel = kernels.ios; };
|
isiOS = { kernel = kernels.ios; };
|
||||||
Linux = { kernel = kernels.linux; };
|
isLinux = { kernel = kernels.linux; };
|
||||||
SunOS = { kernel = kernels.solaris; };
|
isSunOS = { kernel = kernels.solaris; };
|
||||||
FreeBSD = { kernel = kernels.freebsd; };
|
isFreeBSD = { kernel = kernels.freebsd; };
|
||||||
Hurd = { kernel = kernels.hurd; };
|
isHurd = { kernel = kernels.hurd; };
|
||||||
NetBSD = { kernel = kernels.netbsd; };
|
isNetBSD = { kernel = kernels.netbsd; };
|
||||||
OpenBSD = { kernel = kernels.openbsd; };
|
isOpenBSD = { kernel = kernels.openbsd; };
|
||||||
Windows = { kernel = kernels.windows; };
|
isWindows = { kernel = kernels.windows; };
|
||||||
Cygwin = { kernel = kernels.windows; abi = abis.cygnus; };
|
isCygwin = { kernel = kernels.windows; abi = abis.cygnus; };
|
||||||
MinGW = { kernel = kernels.windows; abi = abis.gnu; };
|
isMinGW = { kernel = kernels.windows; abi = abis.gnu; };
|
||||||
|
|
||||||
Android = [ { abi = abis.android; } { abi = abis.androideabi; } ];
|
isAndroid = [ { abi = abis.android; } { abi = abis.androideabi; } ];
|
||||||
Musl = with abis; map (a: { abi = a; }) [ musl musleabi musleabihf ];
|
isMusl = with abis; map (a: { abi = a; }) [ musl musleabi musleabihf ];
|
||||||
|
|
||||||
Kexecable = map (family: { kernel = kernels.linux; cpu.family = family; })
|
isKexecable = map (family: { kernel = kernels.linux; cpu.family = family; })
|
||||||
[ "x86" "arm" "aarch64" "mips" ];
|
[ "x86" "arm" "aarch64" "mips" ];
|
||||||
Efi = map (family: { cpu.family = family; })
|
isEfi = map (family: { cpu.family = family; })
|
||||||
[ "x86" "arm" "aarch64" ];
|
[ "x86" "arm" "aarch64" ];
|
||||||
Seccomputable = map (family: { kernel = kernels.linux; cpu.family = family; })
|
isSeccomputable = map (family: { kernel = kernels.linux; cpu.family = family; })
|
||||||
[ "x86" "arm" "aarch64" "mips" ];
|
[ "x86" "arm" "aarch64" "mips" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
matchAnyAttrs = patterns:
|
matchAnyAttrs = patterns:
|
||||||
if builtins.isList patterns then attrs: any (pattern: matchAttrs pattern attrs) patterns
|
if builtins.isList patterns then attrs: any (pattern: matchAttrs pattern attrs) patterns
|
||||||
else matchAttrs patterns;
|
else matchAttrs patterns;
|
||||||
|
|
||||||
predicates = mapAttrs'
|
predicates = mapAttrs (_: matchAnyAttrs) patterns;
|
||||||
(name: value: nameValuePair ("is" + name) (matchAnyAttrs value))
|
|
||||||
patterns;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue