summary refs log tree commit diff
path: root/lib/systems/inspect.nix
blob: 4cdd26295471d646b4a6d7d33d9ad71eed997200 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{ lib }:
with import ./parse.nix { inherit lib; };
with lib.attrsets;
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; }; }; };
    Darwin       = { kernel = { families = { inherit (kernelFamilies) darwin; }; }; };
    Unix         = [ BSD Darwin Linux SunOS Hurd Cygwin ];

    MacOS        = { kernel = kernels.macos; };
    iOS          = { kernel = kernels.ios; };
    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" ];
  };

  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;
}