update Nix file

This commit is contained in:
Denis Lehmann 2021-03-11 18:39:06 +01:00
parent c911f811c0
commit ddbd25512a
2 changed files with 37 additions and 20 deletions

View File

@ -1,20 +0,0 @@
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "myPythonEnv";
buildInputs = with pkgs; [
python37Full
python37Packages.virtualenv
];
src = null;
shellHook = ''
if [ ! -d .venv ]; then
python -m venv .venv
fi
source .venv/bin/activate
pip install --upgrade pip
if [ -s requirements.txt ]; then
pip install -r requirements.txt
fi
'';
}

37
shell.nix Normal file
View File

@ -0,0 +1,37 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
name = "python-environment";
buildInputs = with pkgs; [
python3
python3Packages.virtualenv
];
shellHook = ''
function log_header {
echo -ne "==> \e[32m\e[1m$1\e[0m\n\n"
}
function log_subheader {
echo -ne "--> \e[33m\e[1m$1\e[0m\n\n"
}
function log {
echo -ne " $1\n"
}
echo ""
log_header "python_environment"
if [ ! -d .venv ]; then
python -m venv .venv
fi
source .venv/bin/activate
log_subheader "upgrading pip"
pip install --upgrade pip
echo ""
if [ -s requirements.txt ]; then
log_subheader "found requirements.txt, installing packages"
pip install -r requirements.txt
echo ""
fi
log_header "package versions"
log "$(python --version)"
log "$(pip --version)"
'';
}