|
| 1 | +let pkgs = import <nixpkgs> {}; |
| 2 | + |
| 3 | + thread-list = list: start: pkgs.lib.lists.foldl (acc: item: (item acc)) start list; |
| 4 | + |
| 5 | + sdk_root = /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk; |
| 6 | + |
| 7 | + xcrun_path = /usr/bin/xcrun; |
| 8 | + |
| 9 | + make_impure_sdk = with pkgs; { lib_path ? null, include_path ? null, framework_path, }: |
| 10 | + let lib_command = pkgs.lib.strings.concatStrings (pkgs.lib.optional (lib_path != null) '' |
| 11 | +if ! [ -x ${lib_path} ]; then |
| 12 | + echo Cannot find command ${lib_path} |
| 13 | + exit 1 |
| 14 | +fi |
| 15 | +ln -s ${lib_path} $out/lib |
| 16 | +''); |
| 17 | + |
| 18 | + include_command = pkgs.lib.strings.concatStrings (pkgs.lib.optional (lib_path != null) '' |
| 19 | +if ! [ -x ${include_path} ]; then |
| 20 | + echo Cannot find command ${include_path} |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | +ln -s ${include_path} $out/include |
| 24 | +''); |
| 25 | + |
| 26 | + script = '' |
| 27 | +mkdir -p $out/Library/ |
| 28 | +
|
| 29 | +${lib_command} |
| 30 | +${include_command} |
| 31 | +if ! [ -x ${framework_path} ]; then |
| 32 | + echo Cannot find command ${framework_path} |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | +ln -s ${framework_path} $out/Library/Frameworks |
| 36 | +''; |
| 37 | + in runCommandLocal "apple-sdk--impure-darwin" { |
| 38 | + __impureHostDeps = [lib_path framework_path framework_path]; |
| 39 | + meta = { |
| 40 | + platforms = lib.platforms.darwin; |
| 41 | + }; |
| 42 | + } script; |
| 43 | + |
| 44 | + mkImpureDrv = with pkgs; name: path: |
| 45 | + let script = '' |
| 46 | +if ! [ -x ${path} ]; then |
| 47 | + echo Cannot find command ${path} |
| 48 | + exit 1 |
| 49 | +fi |
| 50 | +
|
| 51 | +mkdir -p $out/bin |
| 52 | +ln -s ${path} $out/bin/${name} |
| 53 | +''; |
| 54 | + in runCommandLocal "${name}-impure-darwin" { |
| 55 | + __impureHostDeps = [ path ]; |
| 56 | + meta = { |
| 57 | + platforms = lib.platforms.darwin; |
| 58 | + }; |
| 59 | + } script; |
| 60 | + |
| 61 | + impure_apple_sdk = make_impure_sdk { |
| 62 | + lib_path = sdk_root + "/usr/lib"; |
| 63 | + include_path = sdk_root + "/usr/include"; |
| 64 | + framework_path = sdk_root + "/System/Library/Frameworks"; |
| 65 | + }; |
| 66 | + |
| 67 | + filter_apple_sdk = thread-list [ |
| 68 | + (pkgs.lib.lists.filter (it: it != null)) |
| 69 | + (pkgs.lib.lists.filter (it: !(pkgs.lib.strings.hasInfix "apple-framework" it.name))) |
| 70 | + (pkgs.lib.lists.filter (it: !(pkgs.lib.strings.hasInfix "clang-wrapper" it.name))) |
| 71 | + ]; |
| 72 | + |
| 73 | + extra_inputs = [ |
| 74 | + pkgs.clang_15 |
| 75 | + pkgs.tree-sitter |
| 76 | + pkgs.giflib |
| 77 | + (mkImpureDrv "xcrun" xcrun_path) |
| 78 | + impure_apple_sdk |
| 79 | + pkgs.source-code-pro |
| 80 | + pkgs.libjpeg |
| 81 | + pkgs.libtiff |
| 82 | + pkgs.lcms2 |
| 83 | + ]; |
| 84 | +in |
| 85 | +with pkgs; emacs.overrideAttrs (prevAttrs: { |
| 86 | + version = "29"; |
| 87 | + |
| 88 | + SDKROOT = impure_apple_sdk; |
| 89 | + |
| 90 | + CC = pkgs.clang_15; |
| 91 | + |
| 92 | + preConfigure = '' |
| 93 | +# Manually overriding to get access to newer features and the nix version mismatches |
| 94 | +# the host. |
| 95 | +export MACOSX_DEPLOYMENT_TARGET="12.0" |
| 96 | +''; |
| 97 | + |
| 98 | + patches = (prevAttrs.patches) ++ [ |
| 99 | + (pkgs.fetchpatch { |
| 100 | + url = "https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-28/fix-window-role.patch"; |
| 101 | + hash = "sha256-+z/KfsBm1lvZTZNiMbxzXQGRTjkCFO4QPlEK35upjsE="; |
| 102 | + }) |
| 103 | + (pkgs.fetchpatch { |
| 104 | + url = "https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-28/system-appearance.patch"; |
| 105 | + hash = "sha256-oM6fXdXCWVcBnNrzXmF0ZMdp8j0pzkLE66WteeCutv8="; |
| 106 | + }) |
| 107 | + ]; |
| 108 | + |
| 109 | + configureFlags = prevAttrs.configureFlags ++ [ |
| 110 | + "--with-ns" |
| 111 | + "--without-libgmp" |
| 112 | + "--with-tree-sitter" |
| 113 | + ]; |
| 114 | + |
| 115 | + buildInputs = (filter_apple_sdk prevAttrs.buildInputs) ++ extra_inputs; |
| 116 | + |
| 117 | + nativeBuildInputs = (filter_apple_sdk prevAttrs.nativeBuildInputs) ++ extra_inputs; |
| 118 | + |
| 119 | + src = ./.; |
| 120 | +}) |
0 commit comments