Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vim-utils: fix vim-plug plugins #138349

Merged
merged 1 commit into from
Sep 18, 2021
Merged

vim-utils: fix vim-plug plugins #138349

merged 1 commit into from
Sep 18, 2021

Conversation

anirudhb
Copy link
Contributor

@anirudhb anirudhb commented Sep 18, 2021

vim-plug seems to not tolerate paths like /nix/store/j67cqwvfrpq89ijvjdf1rhnk696hjv92-vimplugin-deoplete.nvim-2021-09-02/./.. This PR adds a simple helper that strips the /. off, which makes vim-plug happy and able to load the plugin.

Motivation for this change

vim-plug seems to have broke

Should close #138084

Things done

Added a helper to strip repeated /. from paths. This is used when generating the Plug lines.

  • Built with on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Tested by building a home-manager nvimrc which makes use of this
  • 21.11 Release Notes (or backporting 21.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

For some reason vim-plug doesn't seem to like that. This fixes it so
that it can properly load the plugins.
@anirudhb anirudhb requested a review from jonringer as a code owner September 18, 2021 01:26
@anirudhb anirudhb changed the title pkgs.misc.vim-plugins.vim-utils: fix vim-plug plugins pkgs/misc/vim-plugins/vim-utils: fix vim-plug plugins Sep 18, 2021
@anirudhb anirudhb changed the title pkgs/misc/vim-plugins/vim-utils: fix vim-plug plugins vim-utils: fix vim-plug plugins Sep 18, 2021
@figsoda
Copy link
Member

figsoda commented Sep 18, 2021

cc @teto
@ofborg build neovim.tests

@teto
Copy link
Member

teto commented Sep 18, 2021

very cool you could find the issue, I had dismissed this since the neovim.test.run_nvim_with_plug seemed to work. I think one better approach would be to remove path ? ".", from the buildVimPlugin function (it's easy enough to run as a postprocess) but I can do this later: best to fix the issue ASAP

@ursi
Copy link
Contributor

ursi commented Sep 27, 2021

When I build my system from this commit, I get

error: attribute 'pname' missing

       at /nix/store/p4vj87ss3lk9ickvgvfi0ly1p4kadlva-source/pkgs/misc/vim-plugins/vim-utils.nix:201:50:

          200|     linkVimlPlugin = plugin: packageName: dir: ''
          201|       mkdir -p $out/pack/${packageName}/${dir}/${plugin.pname}
             |                                                  ^
          202|       ln -sf ${plugin}/${rtpPath}/* $out/pack/${packageName}/${dir}/${plugin.pname}

@teto
Copy link
Member

teto commented Sep 27, 2021

@ursi, pname is now mandatory so if you have some custom plugin without it, you should update it

@ursi
Copy link
Contributor

ursi commented Sep 27, 2021

@teto Thanks for that! that was, indeed, the issue. However, after fixing that, gruvbox, (declared with plug.plugins = [ pkgs.vimPlugins.gruvbox ];) still does not work.

@figsoda
Copy link
Member

figsoda commented Sep 27, 2021

I merged a pr that makes pname not mandatory, should be in nixos-unstable already, see #138406

@baloo
Copy link
Member

baloo commented Oct 1, 2021

That actually broke things like:

    vimConfigured = nixpkgs.neovim.override {
      withRuby = false;
      configure = {
        customRC = ''
          set mouse=
          let g:rustfmt_autosave = 1
        '';

        plug.plugins = with nixpkgs.vimPlugins; [
          rust-vim
          syntastic
        ];
      };
    };

I get a plug path in the vim config that does not exists. It seems to work fine when I revert this PR.

@baloo
Copy link
Member

baloo commented Oct 1, 2021

Derivation with the commit:

$ nix show-derivation /nix/store/7s9zxf6rg8p5nfs9ca3niv7qvaai60ch-init.vim
{
  "/nix/store/snbpvpfikrsf816njd5gbx9py0fh3407-init.vim.drv": {
    "outputs": {
      "out": {
        "path": "/nix/store/7s9zxf6rg8p5nfs9ca3niv7qvaai60ch-init.vim"
      }
    },
    "inputSrcs": [
      "/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"
    ],
    "inputDrvs": {
      "/nix/store/8q5ib7b8mmbmspsj1vd79hcm2jqgmy1g-stdenv-linux.drv": [
        "out"
      ],
      "/nix/store/mvpyd6yh596hk48h6czayg929amxxcxp-bash-5.1-p8.drv": [
        "out"
      ],
      "/nix/store/n0l50x7ljvi91lbkqzfnsmxi72zb5vh0-vimplugin-vim-plug-2021-08-31.drv": [
        "out"
      ]
    },
    "system": "x86_64-linux",
    "builder": "/nix/store/qfb4j7w2fjjq953nd9xncz5mymj5n0kb-bash-5.1-p8/bin/bash",
    "args": [
      "-e",
      "/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"
    ],
    "env": {
      "allowSubstitutes": "",
      "buildCommand": "n=$out\nmkdir -p \"$(dirname \"$n\")\"\n\nif [ -e \"$textPath\" ]; then\n  mv \"$textPath\" \"$n\"\nelse\n  echo -n \"$text\" > \"$n\"\nfi\n\neval \"$checkPhase\"\n\n(test -n \"$executable\" && chmod +x \"$n\") || true\n",
      "buildInputs": "",
      "builder": "/nix/store/qfb4j7w2fjjq953nd9xncz5mymj5n0kb-bash-5.1-p8/bin/bash",
      "checkPhase": "",
      "configureFlags": "",
      "depsBuildBuild": "",
      "depsBuildBuildPropagated": "",
      "depsBuildTarget": "",
      "depsBuildTargetPropagated": "",
      "depsHostHost": "",
      "depsHostHostPropagated": "",
      "depsTargetTarget": "",
      "depsTargetTargetPropagated": "",
      "doCheck": "",
      "doInstallCheck": "",
      "executable": "",
      "name": "init.vim",
      "nativeBuildInputs": "",
      "out": "/nix/store/7s9zxf6rg8p5nfs9ca3niv7qvaai60ch-init.vim",
      "outputs": "out",
      "passAsFile": "buildCommand text",
      "patches": "",
      "preferLocalBuild": "1",
      "propagatedBuildInputs": "",
      "propagatedNativeBuildInputs": "",
      "stdenv": "/nix/store/73nigiv9rb0j2m42r93xji4rc3f0kwp1-stdenv-linux",
      "strictDeps": "",
      "system": "x86_64-linux",
      "text": "\" configuration generated by NIX\nset nocompatible\n\nsource /nix/store/jnz6bnfg6d9aqwzh9gbj3hm5yyxprs4q-vimplugin-vim-plug-2021-08-31/plug.vim\nsilent! call plug#begin('/dev/null')\n\nPlug '/nix/store/8ch6mlj4hm6fm6b3zfv84j5jhqifvm3p-vimplugin-rust.vim-2021-09-04'\nPlug '/nix/store/8i7wcakn9n3z6paw95wzyl5ra8cp3f2z-vimplugin-syntastic-2021-09-06'\ncall plug#end()\n\nset mouse=\nlet g:rustfmt_autosave = 1\nlet g:rustfmt_fail_silently = 0\n"
    }
  }
}

Derivation without the commit:

$ nix show-derivation /nix/store/g9dndlcrgf5ld29knj1lmcwg4b94ivn2-init.vim
{
  "/nix/store/i7cwkpp1sjvsimm8gsvs04syxa8pvxfn-init.vim.drv": {
    "outputs": {
      "out": {
        "path": "/nix/store/g9dndlcrgf5ld29knj1lmcwg4b94ivn2-init.vim"
      }
    },
    "inputSrcs": [
      "/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"
    ],
    "inputDrvs": {
      "/nix/store/8q5ib7b8mmbmspsj1vd79hcm2jqgmy1g-stdenv-linux.drv": [
        "out"
      ],
      "/nix/store/fzg5mary1raqjz4z2jjmcnfvfwjhyayz-vimplugin-rust.vim-2021-09-04.drv": [
        "out"
      ],
      "/nix/store/injvs8nfc4xlyr4n971v9abw8ali97ia-vimplugin-syntastic-2021-09-06.drv": [
        "out"
      ],
      "/nix/store/mvpyd6yh596hk48h6czayg929amxxcxp-bash-5.1-p8.drv": [
        "out"
      ],
      "/nix/store/n0l50x7ljvi91lbkqzfnsmxi72zb5vh0-vimplugin-vim-plug-2021-08-31.drv": [
        "out"
      ]
    },
    "system": "x86_64-linux",
    "builder": "/nix/store/qfb4j7w2fjjq953nd9xncz5mymj5n0kb-bash-5.1-p8/bin/bash",
    "args": [
      "-e",
      "/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"
    ],
    "env": {
      "allowSubstitutes": "",
      "buildCommand": "n=$out\nmkdir -p \"$(dirname \"$n\")\"\n\nif [ -e \"$textPath\" ]; then\n  mv \"$textPath\" \"$n\"\nelse\n  echo -n \"$text\" > \"$n\"\nfi\n\neval \"$checkPhase\"\n\n(test -n \"$executable\" && chmod +x \"$n\") || true\n",
      "buildInputs": "",
      "builder": "/nix/store/qfb4j7w2fjjq953nd9xncz5mymj5n0kb-bash-5.1-p8/bin/bash",
      "checkPhase": "",
      "configureFlags": "",
      "depsBuildBuild": "",
      "depsBuildBuildPropagated": "",
      "depsBuildTarget": "",
      "depsBuildTargetPropagated": "",
      "depsHostHost": "",
      "depsHostHostPropagated": "",
      "depsTargetTarget": "",
      "depsTargetTargetPropagated": "",
      "doCheck": "",
      "doInstallCheck": "",
      "executable": "",
      "name": "init.vim",
      "nativeBuildInputs": "",
      "out": "/nix/store/g9dndlcrgf5ld29knj1lmcwg4b94ivn2-init.vim",
      "outputs": "out",
      "passAsFile": "buildCommand text",
      "patches": "",
      "preferLocalBuild": "1",
      "propagatedBuildInputs": "",
      "propagatedNativeBuildInputs": "",
      "stdenv": "/nix/store/73nigiv9rb0j2m42r93xji4rc3f0kwp1-stdenv-linux",
      "strictDeps": "",
      "system": "x86_64-linux",
      "text": "\" configuration generated by NIX\nset nocompatible\n\nsource /nix/store/jnz6bnfg6d9aqwzh9gbj3hm5yyxprs4q-vimplugin-vim-plug-2021-08-31/plug.vim\nsilent! call plug#begin('/dev/null')\n\nPlug '/nix/store/8ch6mlj4hm6fm6b3zfv84j5jhqifvm3p-vimplugin-rust.vim-2021-09-04'\nPlug '/nix/store/8i7wcakn9n3z6paw95wzyl5ra8cp3f2z-vimplugin-syntastic-2021-09-06'\ncall plug#end()\n\nset mouse=\nlet g:rustfmt_autosave = 1\nlet g:rustfmt_fail_silently = 0\n"
    }
  }
}

Looks like the commit makes nix not reference the plugin itself anymore. Thus it does not get built.

@baloo
Copy link
Member

baloo commented Oct 1, 2021

diff --git a/pkgs/misc/vim-plugins/vim-utils.nix b/pkgs/misc/vim-plugins/vim-utils.nix
index 60b9b60806d..c78af017e5b 100644
--- a/pkgs/misc/vim-plugins/vim-utils.nix
+++ b/pkgs/misc/vim-plugins/vim-utils.nix
@@ -294,12 +294,22 @@ let
       */
       /* Remove repeated "/." suffixes from a path */
       stripDots = path: lib.head (builtins.split "(/\\.)*$" path);
+      plugFormat = path:
+        let
+          stripped = stripDots path;
+        in if stripped == path then
+          "Plug '${path}'"
+        else
+          /* path is here duplicated to ensure we still reference the full
+             path in the nix derivation, once rewriten with stripDots, the
+             edge is removed. */
+          "\"from ${path}\nPlug '${stripped}'";
       plugImpl =
       (''
         source ${vimPlugins.vim-plug.rtp}/plug.vim
         silent! call plug#begin('/dev/null')

-        '' + (lib.concatMapStringsSep "\n" (pkg: "Plug '${stripDots pkg.rtp}'") plug.plugins) + ''
+        '' + (lib.concatMapStringsSep "\n" (pkg: plugFormat pkg.rtp) plug.plugins) + ''

         call plug#end()
       '');

@baloo baloo mentioned this pull request Oct 1, 2021
12 tasks
@Janik-Haag Janik-Haag added the 12. first-time contribution This PR is the author's first one; please be gentle! label Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

coc-nvim (and other plugins in NeoVim) not working after latest update on unstable
6 participants