fork
Configure Feed
Select the types of activity you want to include in your feed.
nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
fork
Configure Feed
Select the types of activity you want to include in your feed.
1{ lib }:
2 let inherit (lib.attrsets) mapAttrs; in
3
4rec {
5 doubles = import ./doubles.nix { inherit lib; };
6 parse = import ./parse.nix { inherit lib; };
7 inspect = import ./inspect.nix { inherit lib; };
8 platforms = import ./platforms.nix { inherit lib; };
9 examples = import ./examples.nix { inherit lib; };
10 architectures = import ./architectures.nix { inherit lib; };
11
12 /* List of all Nix system doubles the nixpkgs flake will expose the package set
13 for. All systems listed here must be supported by nixpkgs as `localSystem`.
14
15 **Warning**: This attribute is considered experimental and is subject to change.
16 */
17 flakeExposed = import ./flake-systems.nix { };
18
19 # Elaborate a `localSystem` or `crossSystem` so that it contains everything
20 # necessary.
21 #
22 # `parsed` is inferred from args, both because there are two options with one
23 # clearly preferred, and to prevent cycles. A simpler fixed point where the RHS
24 # always just used `final.*` would fail on both counts.
25 elaborate = args': let
26 args = if lib.isString args' then { system = args'; }
27 else args';
28 final = {
29 # Prefer to parse `config` as it is strictly more informative.
30 parsed = parse.mkSystemFromString (if args ? config then args.config else args.system);
31 # Either of these can be losslessly-extracted from `parsed` iff parsing succeeds.
32 system = parse.doubleFromSystem final.parsed;
33 config = parse.tripleFromSystem final.parsed;
34 # Determine whether we can execute binaries built for the provided platform.
35 canExecute = platform:
36 final.isAndroid == platform.isAndroid &&
37 parse.isCompatible final.parsed.cpu platform.parsed.cpu
38 && final.parsed.kernel == platform.parsed.kernel;
39 isCompatible = _: throw "2022-05-23: isCompatible has been removed in favor of canExecute, refer to the 22.11 changelog for details";
40 # Derived meta-data
41 libc =
42 /**/ if final.isDarwin then "libSystem"
43 else if final.isMinGW then "msvcrt"
44 else if final.isWasi then "wasilibc"
45 else if final.isRedox then "relibc"
46 else if final.isMusl then "musl"
47 else if final.isUClibc then "uclibc"
48 else if final.isAndroid then "bionic"
49 else if final.isLinux /* default */ then "glibc"
50 else if final.isFreeBSD then "fblibc"
51 else if final.isNetBSD then "nblibc"
52 else if final.isAvr then "avrlibc"
53 else if final.isNone then "newlib"
54 # TODO(@Ericson2314) think more about other operating systems
55 else "native/impure";
56 # Choose what linker we wish to use by default. Someday we might also
57 # choose the C compiler, runtime library, C++ standard library, etc. in
58 # this way, nice and orthogonally, and deprecate `useLLVM`. But due to
59 # the monolithic GCC build we cannot actually make those choices
60 # independently, so we are just doing `linker` and keeping `useLLVM` for
61 # now.
62 linker =
63 /**/ if final.useLLVM or false then "lld"
64 else if final.isDarwin then "cctools"
65 # "bfd" and "gold" both come from GNU binutils. The existence of Gold
66 # is why we use the more obscure "bfd" and not "binutils" for this
67 # choice.
68 else "bfd";
69 extensions = rec {
70 sharedLibrary =
71 /**/ if final.isDarwin then ".dylib"
72 else if final.isWindows then ".dll"
73 else ".so";
74 staticLibrary =
75 /**/ if final.isWindows then ".lib"
76 else ".a";
77 library =
78 /**/ if final.isStatic then staticLibrary
79 else sharedLibrary;
80 executable =
81 /**/ if final.isWindows then ".exe"
82 else "";
83 };
84 # Misc boolean options
85 useAndroidPrebuilt = false;
86 useiOSPrebuilt = false;
87
88 # Output from uname
89 uname = {
90 # uname -s
91 system = {
92 linux = "Linux";
93 windows = "Windows";
94 darwin = "Darwin";
95 netbsd = "NetBSD";
96 freebsd = "FreeBSD";
97 openbsd = "OpenBSD";
98 wasi = "Wasi";
99 redox = "Redox";
100 genode = "Genode";
101 }.${final.parsed.kernel.name} or null;
102
103 # uname -m
104 processor =
105 if final.isPower64
106 then "ppc64${lib.optionalString final.isLittleEndian "le"}"
107 else if final.isPower
108 then "ppc${lib.optionalString final.isLittleEndian "le"}"
109 else if final.isMips64
110 then "mips64" # endianness is *not* included on mips64
111 else final.parsed.cpu.name;
112
113 # uname -r
114 release = null;
115 };
116 isStatic = final.isWasm || final.isRedox;
117
118 # Just a guess, based on `system`
119 inherit
120 ({
121 linux-kernel = args.linux-kernel or {};
122 gcc = args.gcc or {};
123 rustc = args.rust or {};
124 } // platforms.select final)
125 linux-kernel gcc rustc;
126
127 linuxArch =
128 if final.isAarch32 then "arm"
129 else if final.isAarch64 then "arm64"
130 else if final.isx86_32 then "i386"
131 else if final.isx86_64 then "x86_64"
132 # linux kernel does not distinguish microblaze/microblazeel
133 else if final.isMicroBlaze then "microblaze"
134 else if final.isMips32 then "mips"
135 else if final.isMips64 then "mips" # linux kernel does not distinguish mips32/mips64
136 else if final.isPower then "powerpc"
137 else if final.isRiscV then "riscv"
138 else if final.isS390 then "s390"
139 else final.parsed.cpu.name;
140
141 qemuArch =
142 if final.isAarch32 then "arm"
143 else if final.isx86_64 then "x86_64"
144 else if final.isx86 then "i386"
145 else final.uname.processor;
146
147 # Name used by UEFI for architectures.
148 efiArch =
149 if final.isx86_32 then "ia32"
150 else if final.isx86_64 then "x64"
151 else if final.isAarch32 then "arm"
152 else if final.isAarch64 then "aa64"
153 else final.parsed.cpu.name;
154
155 darwinArch = {
156 armv7a = "armv7";
157 aarch64 = "arm64";
158 }.${final.parsed.cpu.name} or final.parsed.cpu.name;
159
160 darwinPlatform =
161 if final.isMacOS then "macos"
162 else if final.isiOS then "ios"
163 else null;
164 # The canonical name for this attribute is darwinSdkVersion, but some
165 # platforms define the old name "sdkVer".
166 darwinSdkVersion = final.sdkVer or (if final.isAarch64 then "11.0" else "10.12");
167 darwinMinVersion = final.darwinSdkVersion;
168 darwinMinVersionVariable =
169 if final.isMacOS then "MACOSX_DEPLOYMENT_TARGET"
170 else if final.isiOS then "IPHONEOS_DEPLOYMENT_TARGET"
171 else null;
172 } // (
173 let
174 selectEmulator = pkgs:
175 let
176 qemu-user = pkgs.qemu.override {
177 smartcardSupport = false;
178 spiceSupport = false;
179 openGLSupport = false;
180 virglSupport = false;
181 vncSupport = false;
182 gtkSupport = false;
183 sdlSupport = false;
184 pulseSupport = false;
185 smbdSupport = false;
186 seccompSupport = false;
187 hostCpuTargets = [ "${final.qemuArch}-linux-user" ];
188 };
189 wine = (pkgs.winePackagesFor "wine${toString final.parsed.cpu.bits}").minimal;
190 in
191 if final.parsed.kernel.name == pkgs.stdenv.hostPlatform.parsed.kernel.name &&
192 pkgs.stdenv.hostPlatform.canExecute final
193 then "${pkgs.runtimeShell} -c '\"$@\"' --"
194 else if final.isWindows
195 then "${wine}/bin/wine${lib.optionalString (final.parsed.cpu.bits == 64) "64"}"
196 else if final.isLinux && pkgs.stdenv.hostPlatform.isLinux
197 then "${qemu-user}/bin/qemu-${final.qemuArch}"
198 else if final.isWasi
199 then "${pkgs.wasmtime}/bin/wasmtime"
200 else if final.isMmix
201 then "${pkgs.mmixware}/bin/mmix"
202 else null;
203 in {
204 emulatorAvailable = pkgs: (selectEmulator pkgs) != null;
205
206 emulator = pkgs:
207 if (final.emulatorAvailable pkgs)
208 then selectEmulator pkgs
209 else throw "Don't know how to run ${final.config} executables.";
210
211 }) // mapAttrs (n: v: v final.parsed) inspect.predicates
212 // mapAttrs (n: v: v final.gcc.arch or "default") architectures.predicates
213 // args;
214 in assert final.useAndroidPrebuilt -> final.isAndroid;
215 assert lib.foldl
216 (pass: { assertion, message }:
217 if assertion final
218 then pass
219 else throw message)
220 true
221 (final.parsed.abi.assertions or []);
222 final;
223}