1 { lib, stdenv, callPackage, vimUtils, buildEnv, makeWrapper }:
4 makeCustomizable = macvim: macvim // {
5 # configure expects the same args as vimUtils.vimrcFile.
6 # This is the same as the value given to neovim.override { configure = … }
7 # or the value of vim-full.customize { vimrcConfig = … }
9 # Note: Like neovim and vim-full, configuring macvim disables the
10 # sourcing of the user's vimrc. Use `customRC = "source $HOME/.vim/vimrc"`
11 # if you want to preserve that behavior.
13 doConfig = config: let
14 vimrcConfig = config // {
15 # always source the bundled system vimrc
18 ${config.beforePlugins or ""}
27 "/Applications/MacVim.app/Contents/MacOS"
28 "/Applications/MacVim.app/Contents/bin"
30 nativeBuildInputs = [ makeWrapper ];
31 # We need to do surgery on the resulting app. We can't just make a wrapper for vim because this
32 # is a GUI app. We need to copy the actual GUI executable image as AppKit uses the loaded image's
33 # path to locate the bundle. We can use symlinks for other executables and resources though.
35 # Replace the Contents/MacOS/MacVim symlink with the original file
36 target=$(readlink $out/Applications/MacVim.app/Contents/MacOS/MacVim)
37 rm $out/Applications/MacVim.app/Contents/MacOS/MacVim
38 cp -a -t $out/Applications/MacVim.app/Contents/MacOS "$target"
40 # Wrap the Vim binary for our vimrc
41 wrapProgram $out/Applications/MacVim.app/Contents/MacOS/Vim \
42 --add-flags "-u ${vimUtils.vimrcFile vimrcConfig}"
44 # Replace each symlink in bin/ with the original. Most of them point at other symlinks
45 # and we need those original symlinks to point into our new app bundle.
46 for prefix in bin Applications/MacVim.app/Contents/bin; do
47 for link in $out/$prefix/*; do
48 target=$(readlink "$link")
49 # don't copy binaries like vimtutor, but we do need mvim
50 [ -L "$target" ] || [ "$(basename "$target")" = mvim ] || continue;
52 cp -a -t $out/$prefix "$target"
58 in lib.makeOverridable (lib.setFunctionArgs doConfig (lib.functionArgs vimUtils.vimrcFile));
60 override = f: makeCustomizable (macvim.override f);
61 overrideAttrs = f: makeCustomizable (macvim.overrideAttrs f);
63 in { inherit makeCustomizable; }