Error: access to absolute path '/nix/store/elements/basic.nix' is forbidden in pure eval mode (use '--impure' to override)

I’ve been using nixvim for quite some time now, it’s been great. Unfortunetly I tried to refactor my code to improve modularity and ran into the following issue when trying to run nix run .#vimMinimal inside my configuration:

error: access to absolute path '/nix/store/elements/basic.nix' is forbidden in pure eval mode (use '--impure' to override)

I’ve tried googling but the most I could find was brinx thread with a similar issue as mine but in the end it seems he didn’t manage to solve it.

I’ve already tried restarting my PC, upgrading Nix, running nix-collect-garbage, but nothing seems to work! I don’t know what am I doing wrong when trying to import some NixOS modules from within the nixvim configuration.

Any help would be greatly appreciated!

I’ve found the fix! Thanks to @ElvishJerricco !

Turns out I was trying to import the module like:

# flake.nix
nixVimModule = {
    module = import "${module}";
};

This importing strategy is unnecesary, internally nixvim usese the NixOS build system to build it’s modules so the code above in the end get’s “imported” twice, I don’t know the technical details of why it worked before, dinamic programming languages for you.

Anyways the fix is simple, don’t import stuff twice!

# flake.nix
nixVimModule = {
     inherit module;
#    module = import "${module}";
};