pypa / virtualenv

Virtual Python Environment builder
https://virtualenv.pypa.io
MIT License
4.8k stars 1.03k forks source link

post-create hooks for discoverers/discovery #2660

Closed RonnyPfannschmidt closed 10 months ago

RonnyPfannschmidt commented 10 months ago

What's the problem this feature will solve?

in nixos a python installation is commonly put into the nix store, however on nixos it can commonly happen that a python installation from the store is removed when its no longer reffered to in a nix profile/gc-root

an effect similar to dist-updates python uninstallation happens with the virtualenvs using such a python gets used after a nix-gc removing the supposedly no longer used python

Describe the solution you'd like

the intended mechanism for nix to ensure a tool used by something imperative/state-full, is to add a gc root to prevent early removal

in order to safely do this the ideal solution would be to enable a post create hook which would allow to invoke the nix tools to add a gc root additionally it seems necessary to ensure the hook is installed in any virtualenv created as otherwise any virtualenv installed in those would exhibit the same issue

Alternative Solutions

scripts surrounding virtualenv where a possible idea, unfortunately that would leave api usages and virtualenv in a virtualenv unfixed

gaborbernat commented 10 months ago

Discussed in detail over Discord, but the conclusion:

This is done by just registering the new nixos custom creators, and making sure the plugin is installed when virtualenv is installed.