haslersn / any-nix-shell

fish and zsh support for the nix run and nix-shell environments of the Nix package manager
MIT License
253 stars 17 forks source link

`nix develop` (flake) support ? #12

Closed drupol closed 1 year ago

drupol commented 2 years ago

Hello,

I'm switching my projects and use more and more flakes. When I do nix develop, it starts a bash shell instead of continue to use my current shell on fish.

Do you think it's possible to use any-nix-shell so it works with nix develop ?

sbourdeauducq commented 2 years ago

I guess this line needs to be modified: https://github.com/haslersn/any-nix-shell/blob/master/bin/any-nix-shell#L15

sbourdeauducq commented 2 years ago

This indeed fixes it for fish:

--- a/bin/any-nix-shell
+++ b/bin/any-nix-shell
@@ -12,7 +12,7 @@ end

 # Overwrite the nix command
 function nix
-    if test \$argv[1] = shell
+    if test \$argv[1] = shell || test \$argv[1] = develop
         set argv[1] fish
         $(which .any-nix-wrapper) \$argv
     else

The zsh code would need a similar modification.

It displays "[unknown environment]" at the right of the shell prompt though.

drupol commented 2 years ago

How about making a pull request ?

sbourdeauducq commented 2 years ago

.any-nix-wrapper would also need an update, otherwise it seems nix develop gets aliased to nix shell.

haslersn commented 2 years ago

@sbourdeauducq is right. I'm working on it.

haslersn commented 2 years ago

nix develop and the old nix run (Nix 2.0 - 2.3) have very different command line options. Therefore, supporting nix develop would require some larger changes.

@drupol It seems in Nix 2.4 they reintroduced nix shell, which uses the user's default shell, so any-nix-shell is not required. Can you use nix shell instead of nix develop? It seems the Nix developers deliberately made it so that nix develop uses bash, in order to make debugging builds possible.

sbourdeauducq commented 2 years ago

Can you use nix shell instead of nix develop?

Unfortunately nix shell means using pkgs.buildEnv and not pkgs.mkShell. This means you cannot set environment variables in the shell from the flake, and also it appears that some programs such as llvm-config (or build tools using it) misbehave in the forest of symlinks created by pkgs.buildEnv.

It seems the Nix developers deliberately made it so that nix develop uses bash, in order to make debugging builds possible.

Ah yes - that would make sense...

drupol commented 2 years ago

On my side, I found a workaround: nix develop --command fish

evanrelf commented 1 year ago

FYI nix-your-shell has support for nix-develop.

drupol commented 1 year ago

Unable to build it, doesn't look like the maintainer is taking care of the it anymore.

evanrelf commented 1 year ago

You can get the latest release from Nixpkgs:

λ nix build nixpkgs#nix-your-shell

λ ./result/bin/nix-your-shell --version
nix-your-shell 1.1.1