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

Starship prompt broken #483

Closed Dev380 closed 3 months ago

Dev380 commented 3 months ago

Using the regular nix develop command and the vanilla "use flake" shows  impure (nix-shell-env) in the starship prompt as expected. However, this doesn't work with nix-direnv installed. I think the environment variables $IN_NIXSHELL and $name need to be exported for it to work, is there any reason why these and also the rest of the $NIX* env variables aren't exported with nix-direnv? As far as I can tell the regular "use flake" exports them all.

bbenne10 commented 3 months ago

Screenshot 2024-04-08 at 10 11 29 AM

This is starship drawing the prompt and none of the mentioned variables are exported and things work fine. I can't seem to reproduce the problem?

bbenne10 commented 3 months ago

Wait...I just realized that this prompt is not showing the "via ❄️ impure (nix-shell-env)".

The branch I had just prior had that text.

bbenne10 commented 3 months ago

Screenshot 2024-04-08 at 10 25 19 AM

Where flake.nix looks as follows (you'll probably need to subtitute x86_64-darwin for x86_64-linux to try it):

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
  };

  outputs = { self, nixpkgs }: {
    devShells.x86_64-darwin.default = nixpkgs.legacyPackages.x86_64-darwin.mkShell {
      inputsFrom = [ nixpkgs.legacyPackages.x86_64-darwin.hello ];
    };
  };
}

and .envrc contains only use flake.

Dev380 commented 3 months ago

I just tried that in a fresh flake, and it doesn't seem to work still. For some reason, the path var isn't being exported correctly either in the flake I was trying to use, as all the tools I had installed in the dev shell point to the /bin version instead (I'm on arch not nixos). Perhaps this is just my issue. I installed nix-direnv with nix profile, I copy pasted the code into .config/direnv/direnvrc exactly and nothing else is in that file, .envrc only contains "use flake", and I tried both using another shell and nix-direnv-reload (which was exported correctly as it seems like only .direnv/bin was added to the path) but it did not resolve the issue.

bbenne10 commented 3 months ago

This starts to smell like nix-direnv isn't installed correctly.

Two options, pick one:

1) use home-manager and set programs.direnv.enable = true; and programs.direnv.nix-direnv.enable = true (and maybe programs.<your shell>.enable = true;) 2) Uninstall nix-direnv from your profile and use direnv's source_url functionality to get the latest release.

Either of these should work fine and will reduce debugging complexity. We get a lot of requests that boil down to "it wasn't installed right" or "I wasn't actually using nix-direnv", so making sure nix-direnv is installed properly is very important to getting anywhere - in fact, while testing this, I was in a state that was using the vanilla use flake implementation, so it is very easy to get it wrong...

Dev380 commented 3 months ago

I rebooted my system and it seems to work. I guess that was the issue, thanks.