nixvim icon indicating copy to clipboard operation
nixvim copied to clipboard

Paths referenced by plugins.luasnip.from{Lua,Snipmate,Vscode}.*.paths are removed by `nix store gc`

Open cezdro opened this issue 1 year ago • 2 comments

Discussed in https://github.com/nix-community/nixvim/discussions/2162

Originally posted by cezdro September 4, 2024 I configured the snippet path using the relative path like in the example. However, at one point the snippets stopped working and I figured that it happened because Nix thought the directory was only needed at a build time and could now be GC'd (I have nix.gc.automatic enabled). Here is the snippet from the generated init.lua:

require("luasnip.loaders.from_lua").lazy_load({
    ["paths"] = "/nix/store/1wm0qsxvri2pdxd67sxa569inz4pl385-f5jcwka5bpj542475ib1kgfplgnb9x8n-source/modules/home/nvim/plugins/luasnip",
})

require("luasnip.loaders.from_snipmate").lazy_load({
    ["paths"] = "/nix/store/1wm0qsxvri2pdxd67sxa569inz4pl385-f5jcwka5bpj542475ib1kgfplgnb9x8n-source/modules/home/nvim/plugins/luasnip",
})

require("luasnip.loaders.from_vscode").lazy_load({
    ["paths"] = "/nix/store/1wm0qsxvri2pdxd67sxa569inz4pl385-f5jcwka5bpj542475ib1kgfplgnb9x8n-source/modules/home/nvim/plugins/luasnip",
})

I don't know how Nix decides whether the referenced path should be kept or not. ~I think that if I used mkDerivation the directory wouldn't be treated as a garbage, but I don't think that such thing should be necessary in Nixvim config.~

~I wrote this in Discussions, because I don't know if this is my fault and if it can be improved in Nixvim.~


When I created a derivation like this, it wasn't removed on nix store gc:

{ pkgs, ... }: let
  snippets = pkgs.stdenv.mkDerivation {
    name = "snippets";

    src = ./.;

    buildCommand = ''
      mkdir $out
      cp -r $src/*.{json,lua,snippets} $out
    '';
  };
in {
  programs.nixvim = {
    plugins.luasnip = {
      enable = true;

      fromLua = [{paths = "${snippets}";}];
      fromSnipmate = [{paths = "${snippets}";}];
      fromVscode = [{paths = "${snippets}";}];
    };
  };
}

I think Nixvim could do something like this automatically

cezdro avatar Sep 06 '24 06:09 cezdro