Created
January 23, 2024 06:54
-
-
Save mdipierro/8a7f7d55df6330f776d45ed2bbcdb6c1 to your computer and use it in GitHub Desktop.
Python script that makes its own nix-shell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/bash | |
"""": | |
# if Nix not installed, install it, then rerun this script with nix-shell | |
[ -f /etc/nix/nix.conf ] || curl -L https://nixos.org/nix/install | sh -s -- --daemon | |
exec nix-shell --command "python $0 $@" \ | |
-p python311 \ | |
-p python3Packages.numpy | |
# add any package you want above and they will be added to the shell | |
exit 1 | |
""" #" | |
import numpy | |
print(numpy.array([1,2,3])) |
nix installs itself in /nix/store/ it then installs python311 and and
packages in there. each package goes in its own uniquely named subfolder,
does not conflict with anything, and does not change any system config
file. the script is run in a shell that only exposes declared dependencies.
…On Wed, Jan 31, 2024, 20:29 Alexandre B A Villares ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Thanks for sharing! In your example, a new Python 3.11 interpreter is
installed? Also, you show that packages can be installed (like numpy in the
example). Where are those things installed? Are they persistent between
runs of the script (saving execution time) or they have to be reinstalled
each time (saving disk space)?
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/mdipierro/8a7f7d55df6330f776d45ed2bbcdb6c1#gistcomment-4864670>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHLZTZUCJIZVSE7GT5CMUDYRMK4DBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTENZXG4ZTGOBSU52HE2LHM5SXFJTDOJSWC5DF>
.
You are receiving this email because you authored the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing! In your example, a new Python 3.11 interpreter is installed? Also, you show that packages can be installed (like numpy in the example). Where are those things installed? Are they persistent between runs of the script (saving execution time) or they have to be reinstalled each time (saving disk space)?