at 15.09-beta 3.3 kB view raw
1# Define the list of system with their properties. Only systems tested for 2# Nixpkgs are listed below 3 4with import ./lists.nix; 5with import ./types.nix; 6with import ./attrsets.nix; 7 8let 9 lib = import ./default.nix; 10 setTypes = type: 11 mapAttrs (name: value: 12 setType type ({inherit name;} // value) 13 ); 14in 15 16rec { 17 18 isSignificantByte = isType "significant-byte"; 19 significantBytes = setTypes "significant-byte" { 20 bigEndian = {}; 21 littleEndian = {}; 22 }; 23 24 25 isCpuType = x: isType "cpu-type" x 26 && elem x.bits [8 16 32 64 128] 27 && (8 < x.bits -> isSignificantByte x.significantByte); 28 29 cpuTypes = with significantBytes; 30 setTypes "cpu-type" { 31 arm = { bits = 32; significantByte = littleEndian; }; 32 armv5tel = { bits = 32; significantByte = littleEndian; }; 33 armv7l = { bits = 32; significantByte = littleEndian; }; 34 i686 = { bits = 32; significantByte = littleEndian; }; 35 powerpc = { bits = 32; significantByte = bigEndian; }; 36 x86_64 = { bits = 64; significantByte = littleEndian; }; 37 }; 38 39 40 isExecFormat = isType "exec-format"; 41 execFormats = setTypes "exec-format" { 42 aout = {}; # a.out 43 elf = {}; 44 macho = {}; 45 pe = {}; 46 unknow = {}; 47 }; 48 49 50 isKernel = isType "kernel"; 51 kernels = with execFormats; 52 setTypes "kernel" { 53 cygwin = { execFormat = pe; }; 54 darwin = { execFormat = macho; }; 55 freebsd = { execFormat = elf; }; 56 linux = { execFormat = elf; }; 57 netbsd = { execFormat = elf; }; 58 none = { execFormat = unknow; }; 59 openbsd = { execFormat = elf; }; 60 win32 = { execFormat = pe; }; 61 }; 62 63 64 isArchitecture = isType "architecture"; 65 architectures = setTypes "architecture" { 66 apple = {}; 67 pc = {}; 68 unknow = {}; 69 }; 70 71 72 isSystem = x: isType "system" x 73 && isCpuType x.cpu 74 && isArchitecture x.arch 75 && isKernel x.kernel; 76 77 mkSystem = { 78 cpu ? cpuTypes.i686, 79 arch ? architectures.pc, 80 kernel ? kernels.linux, 81 name ? "${cpu.name}-${arch.name}-${kernel.name}" 82 }: setType "system" { 83 inherit name cpu arch kernel; 84 }; 85 86 87 isDarwin = matchAttrs { kernel = kernels.darwin; }; 88 isLinux = matchAttrs { kernel = kernels.linux; }; 89 isi686 = matchAttrs { cpu = cpuTypes.i686; }; 90 is64Bit = matchAttrs { cpu = { bits = 64; }; }; 91 92 93 # This should revert the job done by config.guess from the gcc compiler. 94 mkSystemFromString = s: let 95 l = lib.splitString "-" s; 96 97 getCpu = name: 98 attrByPath [name] (throw "Unknow cpuType `${name}'.") 99 cpuTypes; 100 getArch = name: 101 attrByPath [name] (throw "Unknow architecture `${name}'.") 102 architectures; 103 getKernel = name: 104 attrByPath [name] (throw "Unknow kernel `${name}'.") 105 kernels; 106 107 system = 108 if builtins.length l == 2 then 109 mkSystem rec { 110 name = s; 111 cpu = getCpu (head l); 112 arch = 113 if isDarwin system 114 then architectures.apple 115 else architectures.pc; 116 kernel = getKernel (head (tail l)); 117 } 118 else 119 mkSystem { 120 name = s; 121 cpu = getCpu (head l); 122 arch = getArch (head (tail l)); 123 kernel = getKernel (head (tail (tail l))); 124 }; 125 in assert isSystem system; system; 126}