44 # Whether to pre-compile Python 2 bytecode for performance.
45 , compilePy2Bytecode ? false
50 # The build system invokes clang to compile Darwin executables.
51 # In this case, our cc-wrapper must not be used.
52 ccWrapperBypass = runCommandWith {
54 name = "cc-wrapper-bypass";
57 template = writeShellScript "template" ''
58 for (( i=1; i<=$#; i++)); do
60 if [[ "''${!i}" == "-target" && "''${!j}" == *"darwin"* ]]; then
61 # their flags must take precedence
62 exec @unwrapped@ "$@" $NIX_CFLAGS_COMPILE
69 unwrapped_bin=${stdenv.cc.cc}/bin
70 wrapped_bin=${stdenv.cc}/bin
74 unwrapped=$unwrapped_bin/$CC wrapped=$wrapped_bin/$CC \
75 substituteAll $template $out/bin/$CC
76 unwrapped=$unwrapped_bin/$CXX wrapped=$wrapped_bin/$CXX \
77 substituteAll $template $out/bin/$CXX
79 chmod +x $out/bin/$CC $out/bin/$CXX
83 # To find all of them: rg -w wrap_elf
85 # src/native/CMakeLists.txt
102 # src/external/darling-dmg/CMakeLists.txt
105 # src/CoreAudio/CMakeLists.txt
109 in stdenv.mkDerivation {
111 version = "unstable-2024-02-03";
113 src = fetchFromGitHub {
116 rev = "25afbc76428c39c3909e9efcf5caef1140425211";
117 fetchSubmodules = true;
118 hash = "sha256-T0g38loUFv3jHvUu3R3QH9hwP8JVe2al4g4VhXnBDMc=";
121 outputs = [ "out" "sdk" ];
124 # We have to be careful - Patching everything indiscriminately
125 # would affect Darwin scripts as well
126 chmod +x src/external/bootstrap_cmds/migcom.tproj/mig.sh
128 src/external/bootstrap_cmds/migcom.tproj/mig.sh \
129 src/external/darlingserver/scripts \
130 src/external/openssl_certificates/scripts
132 substituteInPlace src/startup/CMakeLists.txt --replace SETUID ""
133 substituteInPlace src/external/basic_cmds/CMakeLists.txt --replace SETGID ""
136 nativeBuildInputs = [
146 ++ lib.optional compilePy2Bytecode python2;
147 buildInputs = wrappedLibs ++ [
150 stdenv.cc.libc.linuxHeaders
153 # Breaks valid paths like
154 # Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
157 # src/external/objc4 forces OBJC_IS_DEBUG_BUILD=1, which conflicts with NDEBUG
158 # TODO: Fix in a better way
159 cmakeBuildType = " ";
163 "-DCOMPILE_PY2_BYTECODE=${if compilePy2Bytecode then "ON" else "OFF"}"
164 "-DDARLINGSERVER_XDG_USER_DIR_CMD=${xdg-user-dirs}/bin/xdg-user-dir"
167 env.NIX_CFLAGS_COMPILE = "-Wno-macro-redefined -Wno-unused-command-line-argument";
169 # Linux .so's are dlopen'd by wrapgen during the build
170 env.LD_LIBRARY_PATH = lib.makeLibraryPath wrappedLibs;
172 # Breaks shebangs of Darwin scripts
173 dontPatchShebangs = true;
176 # Install the SDK as a separate output
179 sdkDir=$(readlink -f ../Developer)
181 while read -r path; do
182 dst="$sdk/Developer/''${path#$sdkDir}"
184 if [[ -L "$path" ]]; then
185 target=$(readlink -m "$path")
186 if [[ -e "$target" && "$target" == "$NIX_BUILD_TOP"* && "$target" != "$sdkDir"* ]]; then
188 cp -r -L "$path" "$dst"
189 elif [[ -e "$target" ]]; then
194 >&2 echo "Ignoring symlink $path -> $target"
196 elif [[ -f $path ]]; then
198 elif [[ -d $path ]]; then
201 done < <(find $sdkDir)
204 cp src/external/cctools-port/cctools/ld64/src/*-ld $sdk/bin
205 cp src/external/cctools-port/cctools/ar/*-{ar,ranlib} $sdk/bin
209 echo "Checking for references to $NIX_STORE in Darling root..."
212 grep -r --exclude=mldr "$NIX_STORE" $out/libexec/darling
216 if [[ $ret == 0 ]]; then
217 echo "Found references to $NIX_STORE in Darling root (see above)"
221 patchelf --add-rpath "${lib.makeLibraryPath wrappedLibs}:${addOpenGLRunpath.driverLink}/lib" \
222 $out/libexec/darling/usr/libexec/darling/mldr
225 passthru.tests.nixos = nixosTests.darling;
228 description = "Open-source Darwin/macOS emulation layer for Linux";
229 homepage = "https://www.darlinghq.org";
230 license = licenses.gpl3Plus;
231 maintainers = with maintainers; [ zhaofengli ];
232 platforms = [ "x86_64-linux" ];
233 mainProgram = "darling";