nix-community / nix-direnv

A fast, persistent use_nix/use_flake implementation for direnv [maintainer=@Mic92 / @bbenne10]
MIT License
1.59k stars 98 forks source link

direnv: error invalid line: use flake #476

Closed txtyash closed 3 months ago

txtyash commented 3 months ago

I had the starter setup for nix-direnv. Absolutely no customizaton but now I added some configuration to ~/.config/direnv/direnv.toml:

[global]
load_dotenv = true

This throws the error: direnv: error invalid line: use flake

bbenne10 commented 3 months ago

This is really more of a direnv bug and should be opened there. nix-direnv is not invoked before direnv blows up with the invalid line error. I am closing this because it is not nix-direnv related.

That being said: Did you move the .envrc to .env? Because that won't work correctly (the .env and .envrc files have differing parsers and semantics).

Further, if you expect that change to do anything, you'd need to remove your .direnvrc, as direnv only loads one of those two files (.envrc if it exists is always preferred. If you set load_dotenv it will look for .env files, but will load .envrc and stop after that without loading .env.)

I agree with the author's sentiments and think you should use the dotenv directive in a .envrc file to explicitly load the .env file in the same directory. It is clearer what is happening and removes ambiguity.

txtyash commented 3 months ago

My problem is solved. While using svelte the env variables from .envrc weren't read(not sure why) but they worked when inside a .env. But now I tried again and .envrc is being read correctly. Thanks!