19 # Try to match MacVim's documented script interface compatibility
25 # Building requires a few system tools to be in PATH.
26 # Some of these we could patch into the relevant source files (such as xcodebuild and
27 # qlmanage) but some are used by Xcode itself and we have no choice but to put them in PATH.
28 # Symlinking them in this way is better than just putting all of /usr/bin in there.
29 buildSymlinks = runCommand "macvim-build-symlinks" { } ''
31 ln -s /usr/bin/xcrun /usr/bin/xcodebuild /usr/bin/tiffutil /usr/bin/qlmanage $out/bin
35 stdenv.mkDerivation (finalAttrs: {
40 src = fetchFromGitHub {
43 rev = "release-${finalAttrs.version}";
44 hash = "sha256-L9LVXyeA09aMtNf+b/Oo+eLpeVEKTD1/oNWCiFn5FbU=";
47 enableParallelBuilding = true;
64 patches = [ ./macvim.patch ];
68 "--enable-fail-if-missing"
69 "--with-features=huge"
73 "--enable-luainterp=dynamic"
74 "--enable-python3interp=dynamic"
75 "--enable-perlinterp=dynamic"
76 "--enable-rubyinterp=dynamic"
77 "--enable-tclinterp=yes"
80 "--with-lua-prefix=${luajit}"
81 "--with-python3-command=${python3}/bin/python3"
82 "--with-ruby-command=${ruby}/bin/ruby"
83 "--with-tclsh=${tcl}/bin/tclsh"
85 "--with-compiledby=Nix"
89 # Remove references to Sparkle.framework from the project.
90 # It's unused (we disabled it with --disable-sparkle) and this avoids
91 # copying the unnecessary several-megabyte framework into the result.
93 echo "Patching file src/MacVim/MacVim.xcodeproj/project.pbxproj"
94 sed -e '/Sparkle\.framework/d' -i src/MacVim/MacVim.xcodeproj/project.pbxproj
97 # This is unfortunate, but we need to use the same compiler as Xcode, but Xcode doesn't provide a
98 # way to configure the compiler. We also need to pull in lib/include paths for some of our build
99 # inputs since we don't have cc-wrapper to do that for us.
102 # ideally we'd recurse, but we don't need that right now
103 inputs = [ ncurses ] ++ perl.propagatedBuildInputs;
104 ldflags = map (drv: "-L${lib.getLib drv}/lib") inputs;
105 cppflags = map (drv: "-isystem ${lib.getDev drv}/include") inputs;
108 unset DEVELOPER_DIR # Use the system Xcode not the nixpkgs SDK.
112 DEV_DIR=$(/usr/bin/xcode-select -print-path)/Platforms/MacOSX.platform/Developer
113 configureFlagsArray+=(
114 --with-developer-dir="$DEV_DIR"
115 LDFLAGS=${lib.escapeShellArg ldflags}
116 CPPFLAGS=${lib.escapeShellArg cppflags}
117 CFLAGS="-Wno-error=implicit-function-declaration"
120 # For some reason having LD defined causes PSMTabBarControl to fail at link-time as it
121 # passes arguments to ld that it meant for clang.
125 # When building with nix-daemon, we need to pass -derivedDataPath or else it tries to use
126 # a folder rooted in /var/empty and fails. Unfortunately we can't just pass -derivedDataPath
127 # by itself as this flag requires the use of -scheme or -xctestrun (not sure why), but MacVim
128 # by default just runs `xcodebuild -project src/MacVim/MacVim.xcodeproj`, relying on the default
129 # behavior to build the first target in the project. Experimentally, there seems to be a scheme
130 # called MacVim, so we'll explicitly select that. We also need to specify the configuration too
131 # as the scheme seems to have the wrong default.
133 configureFlagsArray+=(
134 XCODEFLAGS="-scheme MacVim -derivedDataPath $NIX_BUILD_TOP/derivedData"
135 --with-xcodecfg="Release"
139 # Because we're building with system clang, this means we're building against Xcode's SDK and
140 # linking against system libraries. The configure script is picking up Nix Libsystem (via ruby)
141 # so we need to patch that out or we'll get linker issues. The MacVim binary built by Xcode links
142 # against the system anyway so it doesn't really matter that the Vim binary will too. If we
143 # decide that matters, we can always patch it back to the Nix libsystem post-build.
144 # It also picks up libiconv, libunwind, and objc4 from Nix. These seem relatively harmless but
145 # let's strip them out too.
147 # Note: If we do add a post-build install_name_tool patch, we need to add the
148 # "LDFLAGS=-headerpad_max_install_names" flag to configureFlags and either patch it into the
149 # Xcode project or pass it as a flag to xcodebuild as well.
151 substituteInPlace src/auto/config.mk \
152 --replace " -L${stdenv.cc.libc}/lib" "" \
153 --replace " -L${darwin.libobjc}/lib" "" \
154 --replace " -L${darwin.libunwind}/lib" "" \
155 --replace " -L${libiconv}/lib" ""
157 # All the libraries we stripped have -osx- in their name as of this time.
158 # Assert now that this pattern no longer appears in config.mk.
160 while IFS="" read -r line; do
161 if [[ "$line" == LDFLAGS*-osx-* ]]; then
162 echo "WARNING: src/auto/config.mk contains reference to Nix osx library" >&2
164 done <src/auto/config.mk
167 substituteInPlace src/MacVim/vimrc --subst-var-by CSCOPE ${cscope}/bin/cscope
170 # Note that $out/MacVim.app has a misnamed set of binaries in the Contents/bin folder (the V is
171 # capitalized) and is missing a bunch of them. This is why we're grabbing the version from the
174 mkdir -p $out/Applications
175 cp -r src/MacVim/build/Release/MacVim.app $out/Applications
176 rm -rf $out/MacVim.app
179 for prog in ex vi {,g,m,r}vi{m,mdiff,ew}; do
180 ln -s $out/Applications/MacVim.app/Contents/bin/mvim $out/bin/$prog
182 for prog in {,g}vimtutor xxd; do
183 ln -s $out/Applications/MacVim.app/Contents/bin/$prog $out/bin/$prog
185 ln -s $out/Applications/MacVim.app/Contents/bin/gvimtutor $out/bin/mvimtutor
188 ln -s $out/Applications/MacVim.app/Contents/man $out/share/man
191 exe="$out/Applications/MacVim.app/Contents/MacOS/Vim"
192 libperl=$(dirname $(find ${perl} -name "libperl.dylib"))
193 install_name_tool -add_rpath ${luajit}/lib $exe
194 install_name_tool -add_rpath ${tcl}/lib $exe
195 install_name_tool -add_rpath ${python3}/lib $exe
196 install_name_tool -add_rpath $libperl $exe
197 install_name_tool -add_rpath ${ruby}/lib $exe
199 # Remove manpages from tools we aren't providing
200 find $out/Applications/MacVim.app/Contents/man -name evim.1 -delete
203 # We rely on the user's Xcode install to build. It may be located in an arbitrary place, and
204 # it's not clear what system-level components it may require, so for now we'll just allow full
205 # filesystem access. This way the package still can't access the network.
207 (allow file-read* file-write* process-exec mach-lookup)
208 ; block homebrew dependencies
209 (deny file-read* file-write* process-exec mach-lookup (subpath "/usr/local") (with no-log))
213 description = "Vim - the text editor - for macOS";
214 homepage = "https://macvim.org/";
215 license = licenses.vim;
217 platforms = platforms.darwin;
218 hydraPlatforms = [ ]; # hydra can't build this as long as we rely on Xcode and sandboxProfile