-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
"Lighter" and "cleaner" shell for nix develop
and nix shell
#4609
Comments
|
I was initially going to post in agreement with @Ericson2314, but after reviewing the docs I'm unsure. Clearing up messaging and managing expectations seem like preconditions for thinking this through. I have tried to keep my head in the sand on both flakes and new-style commands, so maybe I'm a good rubber duck here...
Main commands:
build build a derivation or fetch a store path
develop run a bash shell that provides the build environment of a derivation
repl start an interactive environment for evaluating Nix expressions
run run a Nix application
shell run a shell in which the specified packages are available I read this as:
|
@abathur yes, For that reason, what @garbas suggests should not apply for |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/always-run-my-shell-in-nix-shell-nix-develop-et-al/12077/3 |
So that we +- get an idea who we're talking about: The "devshell persona" Jeff, age 37, living with his young family in Addis Ababa, Ethiopia, is a guy who is responsible for the productivity of a global team of developers, he is driven by the following:
|
I guess in general there are two major use cases:
For nr. 1 (debug build), it's very simple. One wants to have an environment that is exactly the build environment with all variables and the exact same shell (bash). For nr. 2 (dev environment) it is more difficult to define.
Maybe I'm biased because of frameworks/tools I like to use, but in my opinion a dev environment should not be based on the build environment. It is usually a separate environment with significantly different properties compared to the build environment. If we agree on this, then I guess we might be better of renaming Also Wouldn't it be better if the |
Recently, I've been (ab)using From my point of view, this is what I think I need in a nix shell: For nix package development (I've never really used this sort of thing much. Trying build and looking at the output has generally been adequate for my basic nix packaging needs):
For general development:
At this stage, I'm honestly not sure whether this general development use case is supposed to be supported by |
I'm switching my dev environments from regular I now use In order to continue using fish, I need to do: Is there another way and/or another recommended way to do that? |
I put a |
+1 to de-confusing "I want to debug a nix-based builds" and "I want to use |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: |
Before adding a nix command that is inevitably going to be a bad fit again, consider writing a shell runner derivation that's usable with |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/shell-nix-but-with-flakes/18775/2 |
To add to @Thra11's use-case:
As a C++ developer, my dev shell is typically a superset of my package's inputs, effectively concatenating That gives me all I need to build, test, and run my software in a close reproduction of a I also need to disable (some) hardening, so I can build and debug without optimisations. With Edit: I discovered that the |
Being new to Nix and Flakes, I was confused by the distinction between But when I try the same syntax in a Apologies if this is a totally different issue, but I suspect it's related to misunderstanding of using flakes for building packages vs. for a local development environment. |
This is a known issue that we should resolve. An extensive discussion has occurred in #4715, so "all that remains" is to make a decision.
You probably want
Flakes are (currently) copied to the store before evaluation. If a file is missing, often you'd have to |
That was exactly my problem - I didn't realize the connection between the Nix store and the source tree, even for local dev. Thanks for your help! |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/defining-multiple-nix-shell-environments/25770/1 |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/nix-shell-nix-shell-and-nix-develop/25964/11 |
For those finding this issue via a search engine, if you're just looking to have Add a file at function nix-shell --wraps nix-shell
# if `--run` was passed at the command line, run as-is
for ARG in $argv
if [ "$ARG" = --run ]
command nix-shell $argv
return $status
end
end
# otherwise, append `--run "exec fish"` to the argument list to get a Fish shell
command nix-shell $argv --run "exec fish"
end |
Doesn’t work for |
https://github.com/MercuryTechnologies/nix-your-shell makes |
I did run into #6982, which is strictly-speaking related to See #6982 (comment) for my ugly workaround. |
Since `nix develop -c zsh` already provides all environment variables, the only missing part is a way to run the build phases automatically. A trivial possibility is to create a mini bash script that runs the various phases, that you can call from any shell. I did a proof of concept there and it worked greatly, and is shell agnostic :
https://discourse.nixos.org/t/making-a-development-flake-for-bespoke-synth/29988/5
One could also add in the script a way to save and load the environment/path of the previous command, saved into a file, but this should be quite trivial to do using `env`.
|
Variables can be local, they can be arrays, and they can be functions. This would need something like I doubt that a true solution for shell interoperability should be developed as part of Nix. |
To be honest, I want the opposite. I want the ability to get into a Zsh (or even Bash for that matter) session with just things like If I'm actually running Nix build phases, I'm happy to do so from Bash. It's a Bash environment, and not everything you can do in Bash crosses process boundaries into other shell environments nicely. I don't know whether Nix actually uses any features that wouldn't translate well, and I don't want to have to know that in order to predict the behaviour of the resulting shell environment. I would also much prefer not having to know that there's a big list of environment variables (including generic-sounding names like Aliases for |
Adding onto this: it may not be a bad idea to get inspired by Microsoft's DevContainers. Basically, what I want is to run an isolated, portable development environment I can configure to my liking, without necessarily having to think about packaging it for Nix. I'm looking into Some setting that allowed me to override the command executed (instead of |
In devenv we're exploring this: cachix/devenv#330 (comment) |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/how-to-build-packages-in-nix-develop-nix-shell-with-zsh/58232/1 |
Proposal
Final goal is to provide better integration with other shell environments - eg. zsh, fish, ...
Depending how this will be implemented a very nice to have would be to not spawn a new process when entering shell environment. This would mean the current user shell environment would be updated in-place (like direnv does it).
Reasoning
For those who don't use bash using
nix-shell
,nix develop
ornix shell
usually means you need to runnix-shell --run $SHELL
or creating an alias.I understand there are good reasons for using bash. Using bash ensures that development environments are very predictably and running commands from
nix-shell
would act as close as it can within a sandbox.But on the other side we are forcing developers to use bash or use workarounds. As all debates around editors also debates around shell environments are a hot topic among developers (which is our audience in this case). I wouldn't expect developers switching to bash just so they can use Nix. I would actually expect the opposite, potential users being turned away from Nix due to the lack of good integration with their shell environment.
As with most of the UX decisions also this comes down to compromising one thing over the other.
Bonus
Another bonus to consider is also which environment variables we should expose inside the shell environments.
From the perspective of a developer who just wants to enter a development environments to be able to develop their project, all the extra variables that get created confuse. This "type" of developers are not interested in building a project with Nix, but rather only interested in using Nix to provide needed development environment.
From the perspective of a developer who is working on a tool that will be built later with
nix build
they want to see - especially when packaging -We already have options to ignore environment variables (via
--ignore-environment
flag). We can make this a default and maybe even improve further and provide even "cleaner" development environments.The text was updated successfully, but these errors were encountered: