Equivalent of `nix-shell --run` with `nix shell` or `nix develop`?

Hey folks, I make extensive use of nix-shell --run "pytest --foo --bar" style commands when using shell.nix files. I’ve recently switched to flakes for one of my projects. Now, I’d like to set up CI to run code formatting. Previously I would set up a CI action that runs nix-shell --run "ruff format .". What’s the appropriate way to do this with nix develop?

Through some poking around I’ve found nix develop --command, but it only works on executables, so no arguments, no command chaining, and so forth.

nix shell nixpkgs#package -c package --help i believe is what you’re looking for

Thanks @pbsds ! I’m surprised that

nix develop --command ruff --version

works, but

nix develop --command "ruff --version"

does not.

Is this intentional?

Think so. The old interface took a single arg which it then split, while the new interface takes multiple args which can be passed directly to the subprocess. Less parsing, more secure

How does one run the equivalent of nix-shell --run "foo && bar" in that case?

1 Like

Supposedly the new CLI does not have a notion of running shell command lines but rather exec a program invocation: Rename `nix develop --command` to `nix develop --exec` · Issue #7009 · NixOS/nix · GitHub

Related: nix run should not remove arguments after the first positional one · Issue #6933 · NixOS/nix · GitHub

nix shell nixpkgs#package -c bash -c “foo && bar”