5

I am following this template for configuring my custom vim with Nix. My vim-config/default.nix is as follows:

{ pkgs }:

let
  my_plugins = import ./plugins.nix { inherit (pkgs) vimUtils fetchFromGitHub; };
in with (pkgs // { python = pkgs.python3; }); vim_configurable.customize {
  name = "vim";
  vimrcConfig = {
    customRC = ''
      syntax on
      filetype on
      " ...
    '';

    vam.knownPlugins = vimPlugins // my_plugins;
    vam.pluginDictionaries = [
      { names = [
        "ctrlp"
        # ...
      ]; }
    ];
  };
}

Although there is a (pkgs // { python = pkgs.python3; }) override on line 5, python3 is still not used (when I run vim --version it shows +python -python3). Am I missing anything?

Ben
  • 1,557
  • 13
  • 30

3 Answers3

6

Since there are still people actively looking at this topic, I'll mention that there is an easier solution than the one I first came to:

my_vim_configurable = pkgs.vim_configurable.override {
    python = pkgs.python3;
};

My old answer:

It turns out that with (pkgs // { python = pkgs.python3; }); only modifies python in the scope following the with statement. The python used in vim_configurable is not affected. What I ended up doing is making a python3 version of vim_configurable using vimUtils.makeCustomizable:

vim-config/default.nix:

{ pkgs }:

let
  my_plugins = import ./plugins.nix { inherit (pkgs) vimUtils fetchFromGitHub; };
  configurable_nix_path = <nixpkgs/pkgs/applications/editors/vim/configurable.nix>;
  my_vim_configurable = with pkgs; vimUtils.makeCustomizable (callPackage configurable_nix_path {
    inherit (darwin.apple_sdk.frameworks) CoreServices Cocoa Foundation CoreData;
    inherit (darwin) libobjc cf-private;

    features = "huge"; # one of  tiny, small, normal, big or huge
    lua = pkgs.lua5_1;
    gui = config.vim.gui or "auto";
    python = python3;

    # optional features by flags
    flags = [ "python" "X11" ];
  });

in with pkgs; my_vim_configurable.customize {
  name = "vim";
  vimrcConfig = {
    customRC = ''
      syntax on
      “...
    '';

    vam.knownPlugins = vimPlugins // my_plugins;
    vam.pluginDictionaries = [
      { names = [
        "ctrlp"
        # ...
      ]; }
    ];
  };
}
Russia Must Remove Putin
  • 374,368
  • 89
  • 403
  • 331
Ben
  • 1,557
  • 13
  • 30
  • Thanks, very useful. Removing the double quotes in configurable_nix_path leads to a more efficient (and warningless) evaluation; see https://groups.google.com/forum/#!topic/nix-devel/mPyaxyRShFE – Klaas van Schelven Sep 11 '17 at 11:59
  • Thanks @KlaasvanSchelven, I didn't see the warning myself, but looks like it is a more efficient solution. I've updated the answer to reflect this change. – Ben Sep 12 '17 at 11:37
1

I have found I needed to do the .override before the .customize, like the following, in my systemPackages.

For the benefit of other users going for this, since I wasn't able to find other examples online, here's my entire Vim configuration as of now:

    ((vim_configurable.override {python = python38;}).customize {
      name = "vim";
      # add custom .vimrc lines like this:
      vimrcConfig.customRC = ''
        set nocompatible
        syntax on
        filetype plugin on
        " search in subfolders
        set path+=**
        " tabcomplete files with :find filename
        set wildmenu 
        set relativenumber
        set number
        set shiftwidth=4 expandtab
        set hidden
        set ruler
        set colorcolumn=80 
        set backspace=indent,eol,start
      '';
      vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; {
        # loaded on launch
        start = [ YouCompleteMe elm-vim vim-nix haskell-vim jedi-vim typescript-vim ];
        # manually loadable by calling `:packadd $plugin-name`
        # opt = [ elm-vim vim-nix haskell-vim jedi-vim typescript-vim ];
        # To automatically load a plugin when opening a filetype, add vimrc lines like:
        # autocmd FileType php :packadd phpCompletion
      };
    })

I now have opt commented, with the contents placed in start because lazy loading isn't working with the default loader, and the individual packages loaded with start are supposed to lazy-load anyhow.

I also removed the autocmd parts that are supposed to work with opt (but aren't):

        autocmd FileType elm :packadd elm-vim
        autocmd FileType nix :packadd vim-nix
        autocmd FileType hs  :packadd haskell-vim
        autocmd FileType py  :packadd jedi-vim
        autocmd FileType ts  :packadd typescript-vim
Russia Must Remove Putin
  • 374,368
  • 89
  • 403
  • 331
0

In Darwin(MacOS 10.15) I was not able to compile a vim from vim/configurable due too this error. but I was able to compile it from the more crude version in vim/default.nix.

this is what worked for me:

let 
  pkgs = import <nixpkgs>{};
  vim = import <nixpkgs/pkgs/applications/editors/vim>;
  customVim = (pkgs.callPackage vim {
    inherit (pkgs.darwin.apple_sdk.frameworks) Cocoa Carbon;
  }).overrideDerivation (self : {
    buildInputs = self.buildInputs ++ [ pkgs.python37 ];
    configureFlags = self.configureFlags ++
    [
      #python support
      "--enable-python3interp=yes"
      "--with-python3-config-dir=${pkgs.python37}/lib"
      "--with-python3-command=python3.7"
    ];
  });
in customVim
CountOren
  • 844
  • 1
  • 9
  • 27