5

我正在按照这个模板使用 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)。我错过了什么吗?

4

3 回答 3

6

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

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

我的旧答案:

事实证明,with (pkgs // { python = pkgs.python3; });仅在语句python之后的范围内进行修改。with使用pythoninvim_configurable不受影响。我最终做的是制作一个 python3 版本的vim_configurableusing 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"
        # ...
      ]; }
    ];
  };
}
于 2017-04-05T03:34:56.170 回答
0

在 Darwin(MacOS 10.15) 中,由于这个错误,我无法从 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
于 2019-10-24T14:47:56.580 回答
0

我发现我需要.override.customize我的 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放置了内容。startstart

我还删除了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
于 2021-01-11T06:43:39.530 回答