- Install nix on your system
curl https://nixos.org/nix/install | sh
. ~/.nix-profile/etc/profile.d/nix.sh
- Install direnv
nix-env -i direnv
- Add hook into shell by running
eval "$(direnv hook bash)"
, you will need to add this to.bash_profile
to make it presistant
Create a shell.nix file in your project with the following content. This has python 3.7 and pipenv as buildInputs
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "my-python-project";
buildInputs = [ python37 pipenv ];
}
Create a .envrc file with the following content.
use nix
layout_pipenv
Finally if required add the following to your .bash_profile
if you want it to display the pipenv it has activated when you cd into the project.
show_virtual_env() {
if [[ -n "$VIRTUAL_ENV" && -n "$DIRENV_DIR" ]]; then
echo "($(basename $VIRTUAL_ENV))"
fi
}
export -f show_virtual_env
PS1='$(show_virtual_env)'$PS1
What is the
layout_pipenv
for in the.envrc
?