-
-
Notifications
You must be signed in to change notification settings - Fork 15.1k
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
Better documentation for python.buildEnv / virtualenv #5623
Comments
Yes, indeed, there are many ways with Nix. Best practices are opinionated, but I agree we could provide some guidance and differences between the approaches. Imho |
At first glance, I thought |
The very fact that myEnvFun builds an output that can be made a GC root I would also say that using myEnvFun seems cleaner when I try to write |
I agree on the myEnvFun GC root although there is work being done on Shall we take the Python options presented here and put them on the Wiki or On Fri Jan 23 2015 at 6:29:17 AM Michael Raskin [email protected]
|
I am also quite interested in non-NixOS services and even in Of course, pure-functional foundation under NixOS would include direct I agree with you about the future, I only wanted to add some details |
You even left out one option :D ... Since nixos-containers were added, NixOS: The Purely Functional Linux Distribution |
This requires running NixOS, I guess... myEnvFun is portable. |
One can also create GC roots with |
Feel free to add anything to http://nixos.org/nixpkgs/manual/#python and clean up wiki with outdated info :) |
Is there a way to enter a persistent nix-shell, without evaluating the nix expression? Perhaps by sourcing an env-vars file? |
@cillianderoiste sounds like a good thing to add to nix-shell, --persistent which would create a ./nix-shell-env.sh script or something like that and a GC root for the environment, or maybe add it to the nix-env managed stuff. Imperative environment building. |
It would be cool if there is a way to do that, or it can be added, then we could get rid of myEnvFun. |
@cillianderoiste because evaluating nixexprs is slow? |
@iElectric ah no, it's just I don't want to update a build environment just to enter it. For example, (before nixos-containers) I used myEnvFun for environments where I would run buildout to make a plone instance. This can take 30 mins plus. I don't want to change that environment once it's been created, unless I really have to ... otherwise libraries may have been garbage collected or otherwise change in a way that breaks the compiled python c-modules in eggs. I like that myEnvFun decouples the creation of the environment from the loading of the environment for this reason. |
You can have something like |
Nice, but would you want a separate branch or clone of nixpkgs for each environment then? |
I have a feeling it's already possible by setting TMPDIR to the local directory before running nix-shell, and then sourcing env-vars ... but I'd need to test that. |
|
Well, when used together with |
I'll see if I can use it like this and if it works fine I can replace the examples of myEnvFun in the wiki. Perhaps at a later stage we could wrap this functionality up in a --persistent option as @wmertens suggested. |
@edolstra thoughts? |
I had a look at using nix-shell using the clang example in the wiki: https://nixos.org/wiki/Howto_develop_software_on_nixos#Example_1:_Using_nix-shell_to_Initialize_a_Development_Shell
I can exit the nix-shell, and then I was expecting "--out-link gcroot" to create a symlink called "gcroot" pointing to somewhere in /nix/var/nix/gcroots/, but no symlink was created, and I couldn't find anything in /nix/var/nix/gcroots/ that looked related. Keeping copies of nixpkgs around, as @iElectric suggested, is a reasonable option. Just to be clear, I don't personally have a use for myEnvFun any more, so I don't mind if it gets removed, and I'd be happy to remove the parts of the wiki that refer to it. Perhaps nix-rehash or NixUP is the way to go for a persistent development environment outside of NixOS. |
You can create gcroots for each dependency using the following command:
This will create one symlink for each dependency, named Because of this, it's best to put those in a separate directory. The command I use for haskell is similar to this:
That command creates |
Ok now wrap that all up in a script that either runs nix-shell or loads On Thu Feb 12 2015 at 11:22:15 AM Benno Fünfstück [email protected]
|
This looks fine to me. I'll remove references to myEnvFun from the wiki and add a section on how to create persistent environments with nix-shell as discussed here. |
As @bennofs pointed out on IRC, you can use nix-instantiate to create the environment, and nix-shell to load it:
That seems like an elegant replacement for myEnvFun. I'll work on the wiki a bit more to provide some examples and mention some useful environment variables etc. |
It's worth noting though that the nix-shell behaviour used here relies on the ".drv" file having an absolute path (and ending in ".drv") to prevent nix-shell from trying to interpret it as Nix code. This nix-shell behaviour is also - AFAICS - undocumented. |
It took me a while to find out that one can run this to get all dependencies rooted for GC
It is not mentioned in the man page for nix-shell, but I think is worth doing. Unless I am very wrong the
trick just adds a gc-root for the drv file, which is not what I would think of when asking for a "gc rooted nix shell environment." Generating the drv file is definitely not the most time consuming part of running |
I'm writing a Python on Nix tutorial and obviously I want to have up to date info there. At the time of writing I included Anyway, if you like to help writing, please join. It is just a Markdown file, so there shouldn't be any barrier. |
Thanks @FRidh, really appreciated. I'll go through it and leave comments when I find some time :) |
What's the difference between |
|
(triage) has the documentation improved in the meantime? |
Note the tutorial I mentioned has long since been merged into the Nixpkgs manual. I think it contains all relevant information. If not, people can ask for or propose specific parts. |
Thanks to @iElectric we already have some documentation about Python in Nix(OS). However, I find it still confusing when developing Python software with NixOS. There are multiple ways to get things done and it is unclear how they differentiate to each other:
What are the use cases? Is it meant for packaging new software for nixpkgs or also for developing environments?
Is this the preferred way to build developing environments? It works very well for me, even IPython is able to import pyramid.
Is this the same as 2) ? (of course, zlib libjpeg and git are missing in the first example).
If not, what is the correct declarative way for doing this?
Here are some examples from our wiki:
This one use myEnvFun. Why do I need myEnvFun? Just for installing a "permament" environment whereas nix-shell is "on-the-fly" ? Are there more differences?
Another snippet:
Is this obsolete? If not, what is the difference between stdenv.mkDerivation and the other examples above?
Another one:
I don't understand why we introduce
pythonPlone
. Is this really needed? What about something like:?
My workflow is usually something like this one:
I also commit this file to the project repository. This way other developer have the same dev environment. It works for
nix-shell
andnix-env -f default.nix -iA env-foo
. Sometimes I use it in conjunction withpip
andvirtualenv
.Is something wrong with my way?
PS: Is there a way to auto activate a specific virtualenv when using
nix-shell
?The text was updated successfully, but these errors were encountered: