Skip to content

Instantly share code, notes, and snippets.

@clvx
Last active June 21, 2024 17:21
Show Gist options
  • Save clvx/02b438f3af6d263724cf6a9c4e2ea1e6 to your computer and use it in GitHub Desktop.
Save clvx/02b438f3af6d263724cf6a9c4e2ea1e6 to your computer and use it in GitHub Desktop.
with import <nixpkgs> {};
let
#makeShell returns is assigned a _python_ function which returns a derivation
# which is defined between parenthesis ()
makeShell = python: (mkShell {
name = "python-venv";
buildInputs = with python.pkgs; [
ipython
venvShellHook
];
venvDir = ".venv${python.version}";
postShellHook = ''
pip install -r requirements.txt
'';
}
);
in
#from a single derivation to multiple derivations. To run just choose one; otherwise, it will fail when nix-shell is execute.
{
py39 = makeShell python39;
py310 = makeShell python310;
py311 = makeShell python311;
py312 = makeShell python312;
}
## Run the above shell as:
##pyVersion is an attribute of the shell.nix attribute set.
#$pyVersion=
#$nix-shell -A ${pyVersion} --run zsh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment