在 vim_configurable.customize 中用 python3 覆盖 python

Overriding python with python3 in vim_configurable.customize

我正在按照 this 模板使用 Nix 配置我的自定义 vim。我的vim-config/default.nix如下:

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

虽然第5行有(pkgs // { python = pkgs.python3; })覆盖,但是python3还是没有用(我运行vim --version的时候显示+python -python3)。我错过了什么吗?

由于仍然有人在积极关注这个话题,我会提到有一个比我第一次想到的更简单的解决方案:

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

我的旧答案:

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

制作 vim_configurable 的 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"
        # ...
      ]; }
    ];
  };
}

在 Darwin(MacOS 10.15) 中,我也无法从 vim/configurable 编译 vim,因为这个 error。但我能够从 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

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

为了其他用户的利益,由于我无法在网上找到其他示例,这里是我目前的整个 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 加载的各个包无论如何延迟加载。

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

        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