【问题标题】:Overriding python with python3 in vim_configurable.customize在 vim_configurable.customize 中用 python3 覆盖 python
【发布时间】:2017-04-04 02:15:39
【问题描述】:

我正在关注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)。我错过了什么吗?

【问题讨论】:

    标签: python vim nix nixpkgs


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,非常有用。删除 configure_nix_path 中的双引号会导致更有效(且无警告)的评估;见groups.google.com/forum/#!topic/nix-devel/mPyaxyRShFE
    • 感谢@KlaasvanSchelven,我自己没有看到警告,但看起来这是一个更有效的解决方案。我已经更新了答案以反映这一变化。
    【解决方案2】:

    在达尔文(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
    

    【讨论】:

      【解决方案3】:

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

      为了其他用户的利益,由于我无法在网上找到其他示例,这是我现在的整个 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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-05
        • 1970-01-01
        • 2012-02-01
        • 2015-09-07
        • 1970-01-01
        • 2019-07-28
        • 2015-01-20
        • 2020-03-25
        相关资源
        最近更新 更多