nixpkgs/pkgs/applications/editors/vim/configurable.nix

190 lines
6.4 KiB
Nix
Raw Normal View History

{ source ? "default", callPackage, lib, stdenv, ncurses, pkg-config, gettext
2020-11-02 11:26:49 +00:00
, writeText, config, glib, gtk2-x11, gtk3-x11, lua, python3, perl, tcl, ruby
, libX11, libXext, libSM, libXpm, libXt, libXaw, libXau, libXmu
, libICE
, vimPlugins
vim_configurable: restore ability to override python for modules It seems as Python will be fetched from $PATH in Vim 8.1: ``` stat("/home/ma27/bin/python", 0x7ffe57a317b0) = -1 ENOENT (No such file or directory) stat("/run/wrappers/bin/python", 0x7ffe57a317b0) = -1 ENOENT (No such file or directory) stat("/home/ma27/.nix-profile/bin/python", 0x7ffe57a317b0) = -1 ENOENT (No such file or directory) stat("/nix/var/nix/profiles/default/bin/python", 0x7ffe57a317b0) = -1 ENOENT (No such file or directory) stat("/run/current-system/sw/bin/python", {st_mode=S_IFREG|0555, st_size=291, ...}) = 0 readlink("/run/current-system/sw/bin/python", "/nix/store/ggjkqbvwnv7dflkmdgmmp"..., 4096) = 72 ``` This breaks in cases where you want to use a modified Python derivation for the VIM plugins you use in `vim_configurable`: ``` let vim_configurable' = vim_configurable.override { # python with modules for ensime python = python.withPackages (ps: with ps; [ sexpdata websocket_client ]); }; in vim_configurable'.customize { # ... } ``` With VIM 8.0 this worked perfectly fine, now it's necessary to install the modified `python` in $PATH to actually use it, otherwise an error like this arises: ``` [ensime] A dependency is missing, please `pip2 install sexpdata websocket-client` and restart Vim. Press ENTER or type command to continue ``` However it should be possible to pass the modified Python to the modules, the easiest workaround is to write a wrapper which prefixes $PATH to have the Python derivation available.
2018-05-22 13:07:41 +01:00
, makeWrapper
, wrapGAppsHook
, runtimeShell
# apple frameworks
2019-06-19 22:18:39 +01:00
, CoreServices, CoreData, Cocoa, Foundation, libobjc
, features ? "huge" # One of tiny, small, normal, big or huge
, wrapPythonDrv ? false
, guiSupport ? config.vim.gui or (if stdenv.isDarwin then "gtk2" else "gtk3")
, luaSupport ? config.vim.lua or true
, perlSupport ? config.vim.perl or false # Perl interpreter
, pythonSupport ? config.vim.python or true # Python interpreter
, rubySupport ? config.vim.ruby or true # Ruby interpreter
, nlsSupport ? config.vim.nls or false # Enable NLS (gettext())
, tclSupport ? config.vim.tcl or false # Include Tcl interpreter
, multibyteSupport ? config.vim.multibyte or false # Enable multibyte editing support
, cscopeSupport ? config.vim.cscope or true # Enable cscope interface
, netbeansSupport ? config.netbeans or true # Enable NetBeans integration support.
, ximSupport ? config.vim.xim or true # less than 15KB, needed for deadkeys
, darwinSupport ? config.vim.darwin or false # Enable Darwin support
, ftNixSupport ? config.vim.ftNix or true # Add .nix filetype detection and minimal syntax highlighting support
2018-08-19 20:39:10 +01:00
, ...
}:
let
nixosRuntimepath = writeText "nixos-vimrc" ''
set nocompatible
syntax on
function! NixosPluginPath()
let seen = {}
for p in reverse(split($NIX_PROFILES))
for d in split(glob(p . '/share/vim-plugins/*'))
let pluginname = substitute(d, ".*/", "", "")
if !has_key(seen, pluginname)
exec 'set runtimepath^='.d
let after = d."/after"
if isdirectory(after)
exec 'set runtimepath^='.after
endif
let seen[pluginname] = 1
endif
endfor
endfor
endfunction
execute NixosPluginPath()
if filereadable("/etc/vimrc")
source /etc/vimrc
elseif filereadable("/etc/vim/vimrc")
source /etc/vim/vimrc
endif
'';
common = callPackage ./common.nix {};
in stdenv.mkDerivation rec {
pname = "vim_configurable";
inherit (common) version postPatch hardeningDisable enableParallelBuilding meta;
src = builtins.getAttr source {
2019-08-13 22:52:01 +01:00
default = common.src; # latest release
};
2021-01-15 13:21:58 +00:00
patches = [ ./cflags-prune.diff ] ++ lib.optional ftNixSupport ./ft-nix-support.patch;
configureFlags = [
"--enable-gui=${guiSupport}"
"--with-features=${features}"
"--disable-xsmp" # XSMP session management
"--disable-xsmp_interact" # XSMP interaction
"--disable-workshop" # Sun Visual Workshop support
"--disable-sniff" # Sniff interface
"--disable-hangulinput" # Hangul input support
"--disable-fontset" # X fontset output support
"--disable-acl" # ACL support
"--disable-gpm" # GPM (Linux mouse daemon)
"--disable-mzschemeinterp"
"--disable-gtk_check"
"--disable-gtk2_check"
"--disable-gnome_check"
"--disable-motif_check"
"--disable-athena_check"
"--disable-nextaf_check"
"--disable-carbon_check"
"--disable-gtktest"
]
2021-01-15 13:21:58 +00:00
++ lib.optional stdenv.isDarwin
(if darwinSupport then "--enable-darwin" else "--disable-darwin")
2021-01-15 13:21:58 +00:00
++ lib.optionals luaSupport [
2018-08-19 20:39:10 +01:00
"--with-lua-prefix=${lua}"
"--enable-luainterp"
2021-01-15 13:21:58 +00:00
] ++ lib.optional lua.pkgs.isLuaJIT [
"--with-luajit"
]
2021-01-15 13:21:58 +00:00
++ lib.optionals pythonSupport [
2020-11-02 11:26:49 +00:00
"--enable-python3interp=yes"
"--with-python3-config-dir=${python3}/lib"
# Disables Python 2
"--disable-pythoninterp"
]
2021-01-15 13:21:58 +00:00
++ lib.optional nlsSupport "--enable-nls"
++ lib.optional perlSupport "--enable-perlinterp"
++ lib.optional rubySupport "--enable-rubyinterp"
++ lib.optional tclSupport "--enable-tclinterp"
++ lib.optional multibyteSupport "--enable-multibyte"
++ lib.optional cscopeSupport "--enable-cscope"
++ lib.optional netbeansSupport "--enable-netbeans"
++ lib.optional ximSupport "--enable-xim";
nativeBuildInputs = [
pkg-config
]
2021-01-15 13:21:58 +00:00
++ lib.optional wrapPythonDrv makeWrapper
++ lib.optional nlsSupport gettext
++ lib.optional perlSupport perl
++ lib.optional (guiSupport == "gtk3") wrapGAppsHook
;
buildInputs = [ ncurses libX11 libXext libSM libXpm libXt libXaw libXau
libXmu glib libICE ]
2021-01-15 13:21:58 +00:00
++ lib.optional (guiSupport == "gtk2") gtk2-x11
++ lib.optional (guiSupport == "gtk3") gtk3-x11
++ lib.optionals darwinSupport [ CoreServices CoreData Cocoa Foundation libobjc ]
++ lib.optional luaSupport lua
++ lib.optional pythonSupport python3
++ lib.optional tclSupport tcl
++ lib.optional rubySupport ruby;
preConfigure = "" + lib.optionalString ftNixSupport ''
cp ${vimPlugins.vim-nix.src}/ftplugin/nix.vim runtime/ftplugin/nix.vim
cp ${vimPlugins.vim-nix.src}/indent/nix.vim runtime/indent/nix.vim
cp ${vimPlugins.vim-nix.src}/syntax/nix.vim runtime/syntax/nix.vim
'';
preInstall = ''
mkdir -p $out/share/applications $out/share/icons/{hicolor,locolor}/{16x16,32x32,48x48}/apps
'';
postInstall = ''
ln -s $out/bin/vim $out/bin/vi
2021-01-15 13:21:58 +00:00
'' + lib.optionalString stdenv.isLinux ''
patchelf --set-rpath \
2021-01-15 13:21:58 +00:00
"$(patchelf --print-rpath $out/bin/vim):${lib.makeLibraryPath buildInputs}" \
"$out"/bin/vim
if [[ -e "$out"/bin/gvim ]]; then
patchelf --set-rpath \
2021-01-15 13:21:58 +00:00
"$(patchelf --print-rpath $out/bin/vim):${lib.makeLibraryPath buildInputs}" \
"$out"/bin/gvim
fi
ln -sfn '${nixosRuntimepath}' "$out"/share/vim/vimrc
2021-01-15 13:21:58 +00:00
'' + lib.optionalString wrapPythonDrv ''
2020-11-02 11:26:49 +00:00
wrapProgram "$out/bin/vim" --prefix PATH : "${python3}/bin"
2021-01-15 13:21:58 +00:00
'' + lib.optionalString (guiSupport == "gtk3") ''
2018-08-28 11:30:25 +01:00
rewrap () {
rm -f "$out/bin/$1"
echo -e '#!${runtimeShell}\n"'"$out/bin/vim"'" '"$2"' "$@"' > "$out/bin/$1"
2018-08-28 11:30:25 +01:00
chmod a+x "$out/bin/$1"
}
rewrap ex -e
rewrap view -R
rewrap gvim -g
rewrap gex -eg
rewrap gview -Rg
rewrap rvim -Z
rewrap rview -RZ
rewrap rgvim -gZ
2018-08-28 11:30:25 +01:00
rewrap rgview -RgZ
rewrap evim -y
rewrap eview -yR
rewrap vimdiff -d
2018-08-28 11:30:25 +01:00
rewrap gvimdiff -gd
'';
dontStrip = true;
}