any-nix-shell icon indicating copy to clipboard operation
any-nix-shell copied to clipboard

`nix develop` (flake) support ?

Open drupol opened this issue 2 years ago • 8 comments

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 ?

drupol avatar Nov 20 '21 11:11 drupol

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

sbourdeauducq avatar Nov 29 '21 10:11 sbourdeauducq

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.

sbourdeauducq avatar Dec 04 '21 11:12 sbourdeauducq

How about making a pull request ?

drupol avatar Dec 04 '21 11:12 drupol

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

sbourdeauducq avatar Dec 04 '21 12:12 sbourdeauducq

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

haslersn avatar Dec 04 '21 12:12 haslersn

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.

haslersn avatar Dec 04 '21 13:12 haslersn

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...

sbourdeauducq avatar Dec 05 '21 06:12 sbourdeauducq

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

drupol avatar Dec 05 '21 06:12 drupol

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

evanrelf avatar Jun 09 '23 20:06 evanrelf

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

drupol avatar Jun 09 '23 20:06 drupol

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

evanrelf avatar Jun 09 '23 20:06 evanrelf