在vim_configurable.customize中使用python3覆盖python

时间:2017-04-04 02:15:39

标签: python vim nix nixpkgs

我正在关注this模板,以便使用Nix配置我的自定义vim。我的CASCADE如下:

vim-config/default.nix

虽然第5行有{ 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" # ... ]; } ]; }; } 覆盖,但仍未使用python3(当我运行(pkgs // { python = pkgs.python3; })时,它显示vim --version)。我错过了什么吗?

3 个答案:

答案 0 :(得分:4)

事实证明,with (pkgs // { python = pkgs.python3; });仅修改python语句后的范围内的withpython中使用的vim_configurable不受影响。我最终做的是使用vim_configurable制作vimUtils.makeCustomizable的python3版本:

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"
        # ...
      ]; }
    ];
  };
}

编辑(2018年9月27日):由于仍然有人在积极研究这个话题,我会提到有一个更简单的解决方案:

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

答案 1 :(得分:1)

我发现我需要在系统包中的 .override 之前执行 .customize,如下所示。

为了其他用户的利益,因为我无法在网上找到其他示例,这是我目前的整个 Vim 配置:

    ((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
      };
    })

我现在对 opt 进行了评论,内容放在 start 中,因为延迟加载不适用于默认加载器,并且使用 start 加载的各个包应该是延迟加载的- 无论如何加载。

我还删除了应该与 autocmd 一起使用的 opt 部分(但不是):

        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

答案 2 :(得分:0)

在达尔文(MacOS 10.15)中,由于error,我也无法从vim / configurable编译vim。但是我可以从vim / default.nix中的更原始版本进行编译。

这对我有用:

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