55 lines
1.7 KiB
Nix
55 lines
1.7 KiB
Nix
{
|
|
description = "Python dev env (NixOS 25.11) using project-local venv";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
};
|
|
|
|
outputs = { self, nixpkgs, flake-utils }:
|
|
flake-utils.lib.eachDefaultSystem (system:
|
|
let
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
|
|
# Pick your Python version here
|
|
python = pkgs.python311; # or python312, etc.
|
|
in {
|
|
devShells.default = pkgs.mkShell {
|
|
name = "python-venv-shell";
|
|
|
|
packages = [
|
|
python
|
|
pkgs.python311Packages.virtualenv # gives `virtualenv` tool
|
|
];
|
|
|
|
shellHook = ''
|
|
echo "== Nix dev shell (Python $(python --version 2>&1)) =="
|
|
|
|
# Create a venv in .venv if it doesn't exist yet
|
|
if [ ! -d ".venv" ]; then
|
|
echo "Creating local virtualenv in .venv ..."
|
|
python -m venv .venv
|
|
fi
|
|
|
|
# Activate the venv
|
|
echo "Activating .venv"
|
|
. .venv/bin/activate
|
|
|
|
# Tell you what Python/pip you're using
|
|
echo "Using python: $(which python)"
|
|
echo "Using pip: $(which pip)"
|
|
|
|
# Install / update deps from requirements.txt *into .venv*
|
|
if [ -f "requirements.txt" ]; then
|
|
echo "Installing dependencies from requirements.txt into .venv ..."
|
|
pip install -r requirements.txt
|
|
else
|
|
echo "No requirements.txt found in $(pwd)"
|
|
fi
|
|
|
|
# Prompt tweak so you can see when venv is active
|
|
export PS1="(SPARC-venv) $PS1"
|
|
'';
|
|
};
|
|
});
|
|
} |