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

Add support for the 'nix develop' command #34

Closed calebstewart closed 1 month ago

calebstewart commented 3 months ago

This PR is based on the fork mentioned in #30. I chose to make a separate fork instead of using @manuelbb-upb 's fork since theirs included a flake, which doesn't seem necessary to implement this feature. I tested by overriding the nixpkgs version like so:

  any-nix-shell = pkgs.any-nix-shell.overrideAttrs {
    src = inputs.any-nix-shell-with-develop;
  };

where inputs.any-nix-shell-with-develop is from my flake inputs:

{
  inputs = {
    any-nix-shell-with-develop = {
      url = "github:calebstewart/any-nix-shell/add-nix-develop-support";
      flake = false;
    };
  };
}

I use zsh, and don't know/use the other shells supported here much or at all, so this has only been tested in zsh.

haslersn commented 2 months ago

As already argued in https://github.com/haslersn/any-nix-shell/issues/12#issuecomment-986031541, I deliberately didn't support nix develop, because there's already the nix shell command for the case where you want your default shell. Do you disagree with my argument there?

thenbe commented 1 month ago

Let me know if we're not talking about the same thing, but nix develop is used for devshell outputs from a flake.nix. An example would be the devshell shown here (search for the word jq on that page). That devshell, the one with jq, can be activated by running nix develop. But it cannot be activated by running nix shell.

For these kinds of workflows, this PR is required to activate a shell other than bash (such as zsh). Without this PR, one must explicitly call exec zsh in each devshell declaration (across all projects), as can be illustrated in this example. I believe that avoiding this explicit call is the desired behavior behind this PR (and issue).

thenbe commented 1 month ago

fwiw, I also tested this on zsh (it works) using this overlay:

any-nix-shell = prev.any-nix-shell.overrideAttrs (_old: rec {
  version = "2537e5c6901ef934f8f44d61bcfe938b0fc9fa71";
  src = prev.fetchFromGitHub {
    owner = "haslersn";
    repo = "any-nix-shell";
    rev = version;
    sha256 = "sha256-j1DE0WTBGLmBLoPmqST9YVj9Jc4Mp8WXQILmPBzRlbM=";
  };
  patches = [
    (prev.fetchpatch {
      url = "https://github.com/haslersn/any-nix-shell/pull/34.patch";
      sha256 = "sha256-r+sBN/akxip9QJpRzHRMUAUoRHzMlLx4K/SP38OQQOE=";
    })
  ];
});
bryceberger commented 1 month ago

This doesn't work on fish.

> fish --version
fish, version 3.7.1

> nix develop
test: Expected a combining operator like '-a' at index 4
develop = run or test develop = develop
              ^
- (line 11): 
    if test $argv[1] = run or test $argv[1] = develop
       ^
in function 'nix' with arguments 'develop'

The correct syntax is if test $argv[1] = run -o $argv[1] = develop

haslersn commented 1 month ago

@bryceberger it seems there is a semicolon or linebreak missing before the or. Then it would work, right?

bryceberger commented 1 month ago

Yep, any of the three would work.