{ description = "A very basic flake for developing in python"; # Provides abstraction to boiler-code when specifying multi-platform outputs. inputs = { flake-utils.url = "github:numtide/flake-utils"; nixpkgs.url = "github:nixos/nixpkgs"; }; outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; venvDir = "./.venv"; pythonPackages = pkgs.python38Packages; in { devShell = pkgs.mkShell { nativeBuildInputs = with pkgs; [ hello pythonPackages.python ]; shellHook = '' SOURCE_DATE_EPOCH=$(date +%s) if [ -d "${venvDir}" ]; then echo "Skipping venv creation, '${venvDir}' already exists" else echo "Creating new venv environment in path: '${venvDir}'" # Note that the module venv was only introduced in python 3, so for 2.7 # this needs to be replaced with a call to virtualenv ${pythonPackages.python.interpreter} -m venv "${venvDir}" fi # Under some circumstances it might be necessary to add your virtual # environment to PYTHONPATH, which you can do here too; # PYTHONPATH=$PWD/${venvDir}/${pythonPackages.python.sitePackages}/:$PYTHONPATH source "${venvDir}/bin/activate" # As in the previous example, this is optional. pip install -r requirements.txt ''; }; }); }