-
-
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
Why is there no way to run nix-shell
in a chroot and without the user's .bashrc?
#903
Comments
nix-shell
in a chroot?nix-shell
in a chroot and without the users .bashrc?
nix-shell
in a chroot and without the users .bashrc?nix-shell
in a chroot and without the user's .bashrc?
Relevant: #625 |
I submitted a fix a long time ago but it never got merged: #605 |
Great that there's already a fix in #605! If there's any way to draw attention to that I'd like to know whether there's any objection to it, or the PR just lost in the mix. Another context we have where we really want a pure The only interim workaround I can think of is to make a |
I don't know if What I do now is build custom profiles for each of my projects and then change the PATH to the |
Ah, but when switching with What do you recommend a tool like the Haskell stack tool do? It currently generates |
I use If you want a new "pure" environment I would recommend using |
Well the Stack's current approach of dropping into nix-shell (and calling itself inside the nix-shell) helps it access all the nix-built dependencies, but it doesn't do much for purity. @YPares didn't think nix-build should be used to launch stack builds. I don't totally follow that reasoning given that the build output could be trivial or empty in this case and could get garbage collected anyway. I still think that nix-build rather than nix-shell could at least be an alternate mode that I could potentially add to stack -- as long as there is some way of "mounting" specific additional directories into the build environment for a nix-build. But I don't currently know a method for that. To bring it back to this issue -- if nix-build can add a bit of impurity with mounts, then it removes the need for a more pure nix-shell. |
It's the same really, you can use |
Ok, I think I follow that. But is the approach of using a buildEnv any more pure than using nix-shell like stack is doing now? In extreme cases it seems like IO that happens during the compile (like via TemplateHaskell) could touch arbitrary impure state. But maybe we should just do some sandboxing of the call to nix-shell itself. Like changing HOME and clearing env, and maybe chroot'ing ourselves. |
|
+1 |
It doesn't look like bash is being run with the |
I believe this same issue is what causes my Linux Mint 17.2's /etc/bash.bashrc to break nix-shell: |
I can confirm that |
@domenkozar: You labelled this as "feature", but isn't it more "bug"? (Why is "nix-shell --pure ..." sourcing host bashrc files?) Bumping #605. |
Could we not just build a Bash that doesn't source a global profile by default? i.e. get rid of this
|
Since #1147 was closed as a duplicate of this, I was wondering to what extent is the sandboxing features discussed in #179 going to be available to Also what about nixos-containers, where does that fit in between nix-shell and nix-build? |
@CMCDragonkai This definitely brings up an interesting debate. Sandboxing nix-shell by using a chroot absolutely makes sense. It also makes sense one would want to take that to the next step and isolate networking as well. Now I'm pretty sure those 2 features, and everything else available under nix-shell, are the same thing as nixos-containers. If that is actually the case then I think these tools need to be merged. |
Just one minor thing -- since |
Come to think of it.. having an option of keeping unrestricted filesystem access is a useful feature as well. This allows you to keep custom cross-component ties for the dirty experimentation phase, when you develop your piece of software. The chroot-style mandatory purity can actually be counter-productive for such exploratory scenarios, since it raises the friction for makeshift composition (or decomposition) considerably. For example when you have an on-going experiment with splitting your package in two, you might want to symlink stuff around. So I guess it's a no-no to let the shell environment's dependencies (especially such as |
It should be compositional. You start with the minimum-level of isolation, and you should be able to "functionally" compose extra levels of isolation and mix-and-match what you want. This would take a lot of steam away from docker like tools, since they are often heavy weight all or nothing things. At the beginning maybe I just want certain packages available, then maybe I want a custom FS, then maybe network namespaces, then maybe PID namespace, then maybe resource isolation.... etc. Making these things compose will preserve the simplicity and exploratory nature of nix-shell without making it too complex immediately. |
One difficulty is that In the debugging scenario, a build has failed and the developer wants to figure out why. He could edit the nix code and re-run the build but that isn't necessarily fast. In that scenario I believe that a In the dynamic profile scenario, the user just wants a bunch of tools and environment variables setup to work on a source tree. Ideally that environment can be pinned to avoid uncontrolled rebuilds when the channel is updated. Even better would be to have an activation script to start project-related services like postgresql and redis. |
are there clear step by step instructions somewhere for a nix noob like myself to get into a shell that has my deps from this is hurting adoption in my team as people already have rust installed under their user, i'm sure there is some solution (like |
@thedavidmeister do you have user namespaces? Also, where is your Nixpkgs checkout located? I could try writing an nsjail command for running nix-shell in a much-pruned environment (I use nsjail to sandbox Firefox so I had to learn most of the flags)… |
@7c6f434c i don't know? my situation is that i've asked my team to install nix on their existing machines (ubuntu and mac) with:
as per https://nixos.org/nix/download.html then i ask them to run https://github.com/holochain/holochain-rust and then run a command like if the team member has already used what i'm expecting/hoping is that i can ask a team member to install |
@7c6f434c i don't know?
my situation is that i've asked my team to install nix on their existing machines (ubuntu and mac) with:
Oh, macs… if you need to cover macOS, nsjail should not be suitable.
|
@7c6f434c well, is there at least an ubuntu solution? i'm interested in this nsjail idea |
This needs a Nixpkgs checkout made with git clone, and only passes through
|
Can we add an option to disable the |
Also, FWIW, setting |
edit: |
I marked this as stale due to inactivity. → More info |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/building-nixpkgs-from-scratch-on-non-nixos/16962/1 |
I marked this as stale due to inactivity. → More info |
This is still a desired feature. |
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/speeding-up-similar-builds-with-oci-layers/45285/6 |
I'm using the Haskell
stack
tool's nix integration, which launches everything through a nix-shell.Even running with
--pure
, nix-shell seems really impure compared to nix-build. It not only mounts directories, it sources the bashrc from the host system!Is there any way to lock down nix-shell more using current configuration options? If not, is there any plan to make
nix-shell
more pure?This is especially concerning because I thought that shebang lines with nix-shell were a great way to get reproducible scripts. But now I realize that those scripts are much more impure and less reproducible than I thought.
The text was updated successfully, but these errors were encountered: