Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Piping commands into nix develop doesn't set up the environment correctly #8468

Open
soenkehahn opened this issue Jun 7, 2023 · 0 comments
Labels
bug nix-shell nix-shell, nix develop, nix print-dev-env, etc

Comments

@soenkehahn
Copy link
Contributor

Describe the bug

I have the following flake.nix file:

{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs";
  inputs.flake-utils.url = "github:numtide/flake-utils";

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let pkgs = nixpkgs.legacyPackages.${system}; in
      {
        devShells.default = pkgs.mkShell {
          buildInputs = [ pkgs.hello ];
        };
      }
    );
}

In I shell I can do this:

$ echo 'hello\nexit' | nix develop -c bash
Hello, world!
$ echo 'hello\nexit' | nix develop
bash: line 1: hello: command not found
$

As you can see, the two commands behave differently. nix develop -c bash allows me to pipe commands into the started shell. This behaves as I would expect it to. nix develop (without -c bash) however doesn't seem to execute the command inside a devShell that is set up correctly. This seems like a bug to me.

Note that piping commands into nix develop does execute commands inside bash, just not inside the right environment. So the following works as expected:

$ echo 'echo foo\nexit' | nix develop
foo
$

Also note that nix develop spawns a bash process with some flags, e.g. bash --rcfile /tmp/nix-shell.zW1tMH. Whereas nix develop -c bash does not. So I'm guessing that's somehow causing the difference in behavior.

Using nix-env (Nix) 2.13.3.

(For me personally, fixing this bug, if it is a bug, doesn't have a high priority. I would be more interested in figuring out why this happens and whether this is in fact a bug or intended behavior.)

Priorities

Add 👍 to issues you find important.

@soenkehahn soenkehahn added the bug label Jun 7, 2023
@roberth roberth added the nix-shell nix-shell, nix develop, nix print-dev-env, etc label Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug nix-shell nix-shell, nix develop, nix print-dev-env, etc
Projects
None yet
Development

No branches or pull requests

2 participants