24 stdenv.mkDerivation rec {
28 src = fetchFromGitHub {
32 hash = "sha256-VVgJDKf21V7Mkfalh8tJ0Tx73VG1ong+8C6uPC23154=";
44 ] ++ lib.optionals (!stdenv.isDarwin) [
49 "-DMOLD_USE_SYSTEM_MIMALLOC:BOOL=ON"
50 "-DMOLD_USE_SYSTEM_TBB:BOOL=ON"
53 env.NIX_CFLAGS_COMPILE = toString (lib.optionals stdenv.isDarwin [
54 "-faligned-allocation"
58 updateScript = nix-update-script { };
61 helloTest = name: helloMold:
63 command = "$READELF -p .comment ${lib.getExe helloMold}";
64 emulator = stdenv.hostPlatform.emulator buildPackages;
66 runCommandCC "mold-${name}-test" { passthru = { inherit helloMold; }; }
68 echo "Testing running the 'hello' binary which should be linked with 'mold'" >&2
69 ${emulator} ${lib.getExe helloMold}
71 echo "Checking for mold in the '.comment' section" >&2
72 if output=$(${command} 2>&1); then
73 if grep -Fw -- "mold" - <<< "$output"; then
76 echo "No mention of 'mold' detected in the '.comment' section" >&2
77 echo "The command was:" >&2
79 echo "The output was:" >&2
84 echo -n "${command}" >&2
85 echo " returned a non-zero exit code." >&2
93 version = testers.testVersion { package = mold; };
94 } // lib.optionalAttrs stdenv.isLinux {
95 adapter-gcc = helloTest "adapter-gcc" (hello.override (old: { stdenv = useMoldLinker gccStdenv; }));
96 adapter-llvm = helloTest "adapter-llvm" (hello.override (old: { stdenv = useMoldLinker clangStdenv; }));
97 wrapped = helloTest "wrapped" (hello.overrideAttrs (previousAttrs: {
98 nativeBuildInputs = (previousAttrs.nativeBuildInputs or [ ]) ++ [ mold-wrapped ];
99 NIX_CFLAGS_LINK = toString (previousAttrs.NIX_CFLAGS_LINK or "") + " -fuse-ld=mold";
105 description = "A faster drop-in replacement for existing Unix linkers (unwrapped)";
107 mold is a faster drop-in replacement for existing Unix linkers. It is
108 several times faster than the LLVM lld linker. mold is designed to
109 increase developer productivity by reducing build time, especially in
110 rapid debug-edit-rebuild cycles.
112 homepage = "https://github.com/rui314/mold";
113 changelog = "https://github.com/rui314/mold/releases/tag/v${version}";
114 license = licenses.mit;
115 platforms = platforms.unix;
116 mainProgram = "mold";
117 maintainers = with maintainers; [ azahi paveloom ];