summary refs log tree commit diff
path: root/pkgs/applications/editors/vim/configurable.nix
blob: bb3d571e6f865411b3baa2d1744a675f01746e18 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# TODO tidy up eg The patchelf code is patching gvim even if you don't build it..
# but I have gvim with python support now :) - Marc
{ source ? "default", callPackage, stdenv, ncurses, pkgconfig, gettext
, writeText, config, glib, gtk2-x11, gtk3-x11, lua, python, perl, tcl, ruby
, libX11, libXext, libSM, libXpm, libXt, libXaw, libXau, libXmu
, libICE
, vimPlugins
, makeWrapper
, wrapGAppsHook
, runtimeShell

# apple frameworks
, CoreServices, CoreData, Cocoa, Foundation, libobjc

, features          ? "huge" # One of tiny, small, normal, big or huge
, wrapPythonDrv     ? false
, guiSupport        ? config.vim.gui or "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
, ...
}:


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 {};

  isPython3 = python.isPy3 or false;

in stdenv.mkDerivation rec {

  pname = "vim_configurable";

  inherit (common) version postPatch hardeningDisable enableParallelBuilding meta;

  src = builtins.getAttr source {
    default = common.src; # latest release
  };

  patches = [ ./cflags-prune.diff ] ++ stdenv.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"
  ]
  ++ stdenv.lib.optional stdenv.isDarwin
     (if darwinSupport then "--enable-darwin" else "--disable-darwin")
  ++ stdenv.lib.optionals luaSupport [
    "--with-lua-prefix=${lua}"
    "--enable-luainterp"
  ]
  ++ stdenv.lib.optionals pythonSupport [
    "--enable-python${if isPython3 then "3" else ""}interp=yes"
    "--with-python${if isPython3 then "3" else ""}-config-dir=${python}/lib"
    "--disable-python${if (!isPython3) then "3" else ""}interp"
  ]
  ++ stdenv.lib.optional nlsSupport          "--enable-nls"
  ++ stdenv.lib.optional perlSupport         "--enable-perlinterp"
  ++ stdenv.lib.optional rubySupport         "--enable-rubyinterp"
  ++ stdenv.lib.optional tclSupport          "--enable-tclinterp"
  ++ stdenv.lib.optional multibyteSupport    "--enable-multibyte"
  ++ stdenv.lib.optional cscopeSupport       "--enable-cscope"
  ++ stdenv.lib.optional netbeansSupport     "--enable-netbeans"
  ++ stdenv.lib.optional ximSupport          "--enable-xim";

  nativeBuildInputs = [
    pkgconfig
  ]
  ++ stdenv.lib.optional wrapPythonDrv makeWrapper
  ++ stdenv.lib.optional nlsSupport gettext
  ++ stdenv.lib.optional perlSupport perl
  ++ stdenv.lib.optional (guiSupport == "gtk3") wrapGAppsHook
  ;

  buildInputs = [ ncurses libX11 libXext libSM libXpm libXt libXaw libXau
    libXmu glib libICE ]
    ++ stdenv.lib.optional (guiSupport == "gtk2") gtk2-x11
    ++ stdenv.lib.optional (guiSupport == "gtk3") gtk3-x11
    ++ stdenv.lib.optionals darwinSupport [ CoreServices CoreData Cocoa Foundation libobjc ]
    ++ stdenv.lib.optional luaSupport lua
    ++ stdenv.lib.optional pythonSupport python
    ++ stdenv.lib.optional tclSupport tcl
    ++ stdenv.lib.optional rubySupport ruby;

  preConfigure = ''
    '' + stdenv.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
  '' + stdenv.lib.optionalString stdenv.isLinux ''
    patchelf --set-rpath \
      "$(patchelf --print-rpath $out/bin/vim):${stdenv.lib.makeLibraryPath buildInputs}" \
      "$out"/bin/{vim,gvim}

    ln -sfn '${nixosRuntimepath}' "$out"/share/vim/vimrc
  '' + stdenv.lib.optionalString wrapPythonDrv ''
    wrapProgram "$out/bin/vim" --prefix PATH : "${python}/bin"
  '' + stdenv.lib.optionalString (guiSupport == "gtk3") ''

    rewrap () {
      rm -f "$out/bin/$1"
      echo -e '#!${runtimeShell}\n"'"$out/bin/vim"'" '"$2"' "$@"' > "$out/bin/$1"
      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
    rewrap rgview -RgZ
    rewrap evim    -y
    rewrap eview   -yR
    rewrap vimdiff -d
    rewrap gvimdiff -gd
  '';

  dontStrip = true;
}