oxalica/nil

error: cannot build ... because the option 'allow-import-from-derivation' is disabled

Closed this issue · 7 comments

My flake notlua builds json type definitions in a derivation using Lua and imports them back to Nix (via builtins.readJSON'ing the derivation output) to allow easy interop with Lua and NeoVim API. However, that's impossible without allow-import-from-derivation. I understand it may not be desirable for everyone using the LSP, so maybe Nix flags should be configurable via LSP options? Though it's technically already possible by making the binary option a wrapper around nix with correct flags

However, that's impossible without allow-import-from-derivation

It should respect your /etc/nix/nix.conf. Do you disable it on your system somehow?

no, I don't (or I wouldn't be able to use the flake)

Hey, I'm having the same problem, and it's appeared recently without me changing any configuration (except updating versions of nix and nil, of course). It's hard for me to say which version exactly introduced the issue.

I'm importing dream2nix in the flake configuring my hosts to import some global npm packages not found in nixpkgs. The LSP instantly quits for me, with the same error described by chayleaf.

For reference, the flake builds normally with nix build, nix flake show and nix flake check also work without any flags. My /etc/nix/nix.conf looks like this:

allowed-users = *
auto-optimise-store = true
builders = 
cores = 0
extra-sandbox-paths = 
max-jobs = auto
require-sigs = true
sandbox = true
sandbox-fallback = false
substituters = https://nix-community.cachix.org https://hyprland.cachix.org https://cache.nixos.org/
system-features = nixos-test benchmark big-parallel kvm
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc=
trusted-substituters = 
trusted-users = root user
experimental-features = nix-command flakes

So, nothing should be touching that setting. I would be fine with either being able to force enable the option through the lsp configuration, or just always having it enabled. Seems like this would make sense for the LSP, since you'd always want LSP support in projects making use of IFDs.

@chayleaf Have you been able to make a workaround with a wrapper around nix, like you said? I'd be interested in that since nil is currently not usable with my system flake.

Have you been able to make a workaround with a wrapper around nix, like you said?

@happenslol you can use the following:

#!/usr/bin/env bash
nix --allow-import-from-derivation "$@"

as the binary. In my neovim config with the aforementioned notlua I just use:

{
  nil_ls = {
    settings = {
      nil.nix.binary = "${pkgs.writeShellScript "nil-nix-wrapper" ''
        nix --allow-import-from-derivation "$@"
      ''}";
    };   
  };
}

I'm importing dream2nix in the flake configuring my hosts to import some global npm packages not found in nixpkgs. The LSP instantly quits for me, with the same error described by chayleaf.

I cannot reproduce with a dram2nix input (with nil.nix.flake.autoEvalInputs = true since we currently disable that by default). It respects my user config ~/.config/nix/nix.conf, and evaluates when I enable IFD in it.

Does this issue still exist on the current main commit?

The problem must've gotten resolved in a recent update, I can't reproduce this anymore. Thanks anyway for looking into it, feel free to close!

closing this, will reopen if i'm able to reproduce it later (can't check at the moment)