Search code examples
pythonvimnixnixpkgs

Overriding python with python3 in vim_configurable.customize


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?


Solution

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