Skip to content

Instantly share code, notes, and snippets.

@rochecompaan
Created May 16, 2024 11:28
Show Gist options
  • Save rochecompaan/a6458a9e39453bba8e610b6174a8095d to your computer and use it in GitHub Desktop.
Save rochecompaan/a6458a9e39453bba8e610b6174a8095d to your computer and use it in GitHub Desktop.
Flake for Python project on a specific Python version that manages dependencies in requirements.txt
{
description = "wx3 dev environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
# Go to nixhub.io and find the hash of the specific Python version you want to time-travel too
python38.url = "github:NixOS/nixpkgs/nixpkgs/9a9dae8f6319600fa9aebde37f340975cab4b8c0";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils, ... }@inputs:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
venvDir = "./venv";
in {
devShells.default = pkgs.mkShell {
buildInputs = [
inputs.python38.legacyPackages.${system}.python38
];
shellHook = ''
# create a virtualenv if there isn't one.
if [ -d "${venvDir}" ]; then
echo "Skipping venv creation, '${venvDir}' already exists"
else
echo "Creating new venv environment in path: '${venvDir}'"
${inputs.python38.legacyPackages.${system}.python38}/bin/python -m venv --system-site-packages "${venvDir}"
source "${venvDir}/bin/activate"
echo "Installing Python dependencies"
pip install -r setup/requirements.txt -r setup/requirements-dev.txt
fi
# activate our virtual env.
source "${venvDir}/bin/activate"
'';
};
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment