1{ lib
2, stdenv
3, fetchFromGitHub
4, cmake
5, llvmPackages
6, libxml2
7, zlib
8, coreutils
9, callPackage
10, ...
11}:
12
13args:
14
15stdenv.mkDerivation (finalAttrs: {
16 pname = "zig";
17
18 src = fetchFromGitHub {
19 owner = "ziglang";
20 repo = "zig";
21 rev = finalAttrs.version;
22 inherit (args) hash;
23 };
24
25 nativeBuildInputs = [
26 cmake
27 llvmPackages.llvm.dev
28 ];
29
30 buildInputs = [
31 libxml2
32 zlib
33 ] ++ (with llvmPackages; [
34 libclang
35 lld
36 llvm
37 ]);
38
39 env.ZIG_GLOBAL_CACHE_DIR = "$TMPDIR/zig-cache";
40
41 # Zig's build looks at /usr/bin/env to find dynamic linking info. This doesn't
42 # work in Nix's sandbox. Use env from our coreutils instead.
43 postPatch = ''
44 substituteInPlace lib/std/zig/system/NativeTargetInfo.zig \
45 --replace "/usr/bin/env" "${coreutils}/bin/env"
46 '';
47
48 doInstallCheck = true;
49 installCheckPhase = ''
50 runHook preInstallCheck
51
52 $out/bin/zig test --cache-dir "$TMPDIR/zig-test-cache" -I $src/test $src/test/behavior.zig
53
54 runHook postInstallCheck
55 '';
56
57 passthru = {
58 hook = callPackage ./hook.nix {
59 zig = finalAttrs.finalPackage;
60 };
61 };
62
63 meta = {
64 description = "General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software";
65 homepage = "https://ziglang.org/";
66 changelog = "https://ziglang.org/download/${finalAttrs.version}/release-notes.html";
67 license = lib.licenses.mit;
68 maintainers = with lib.maintainers; [ andrewrk ] ++ lib.teams.zig.members;
69 platforms = lib.platforms.unix;
70 };
71} // removeAttrs args [ "hash" ])