Skip to content

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

@cezdro

Description

@cezdro

Discussed in #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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions