How to use nix-expression generators within nix-expression


I’m trying to build a remote plugin for neovim and it requires some node packages being installed.

In my home-manager configuration I have:

vim-todoist = pkgs.vimUtils.buildVimPlugin {
  name = "todoist.nvim";
  src = pkgs.fetchFromGitHub { ... };
plugins = [ vim-todoist ]

It installs the plugin just fine, but now it requires Node.js modules. The repository comes with package.json file and technically I can use node2nix:

  postInstall = ''
    ${pkgs.node2nix}/bin/node2nix    # genrates nix expressions from package.json
    cp *.nix $out/

Now, how do I use generated nix expression? If I try to refer to that file I get a string that refers to a store path cannot be appended to a path. Which kind of makes sense - it doesn’t feel very reproducible. Just storing it separately also feels very bloated.

Although this node2nix-specific question, I think same applies for other generators, like pypi2nix, cabal2nix etc.

So you want “Import From Derivation”? You could just import it, like this:

    drv = <build package that contains nix expressions>;
    import drv;
1 Like

See also GitHub - nix-community/yarn2nix: Generate nix expressions from a yarn.lock file [maintainer=???]

1 Like

@Ninlives apparently… it worked! It seems I had some misunderstanding about relationships between nix expressions and nix store. Thanks!

@pasqui23 thanks! It seems yarn2nix is slightly more expression-oriented than node2nix, which is really cool. However, I’m so rusty in Node.js that I barely caught inception of yarn, so will probably stick with node2nix.

Shouldn’t be too hard to pass from npm to yarn,it uses the same registry and the same package.json