From 5bd5293b4e368f307b0b8af5150d0cf77e4d5878 Mon Sep 17 00:00:00 2001 From: Jesse Cirimelli-Low Date: Mon, 4 May 2026 16:39:33 -0700 Subject: [PATCH] use python venv with nix --- .gitignore | 1 + Makefile | 2 +- flake.nix | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7b0c7889..dc55dac3 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ compiler/tests/results/ open_pdks/ dist/ openram.egg-info/ +.venv/ sky130A sky130B gf180mcuA diff --git a/Makefile b/Makefile index f2c65a15..f20dbdc6 100644 --- a/Makefile +++ b/Makefile @@ -246,5 +246,5 @@ build_library: # Build and install the openram library library: build_library - @python3 -m pip install --force dist/openram*.whl + @python3 -m pip install --force-reinstall dist/openram*.whl .PHONY: library diff --git a/flake.nix b/flake.nix index fa72149d..8c6fcee2 100644 --- a/flake.nix +++ b/flake.nix @@ -38,11 +38,24 @@ pkgs.git pkgs.gnumake pkgs.curl + + # Python + pip (user installs, venvs; prefer Nix where possible) + pkgs.python3 + pkgs.python3Packages.pip ]; shellHook = '' export OPENRAM_USE_CONDA=0 - echo "OpenRAM: using tools from Nix devShell" + # PEP 668: Nix `python3` is externally managed. Put a repo-local venv first on PATH + # so `make library` uses it. Use $PWD (writable checkout), not `toString self` (nix store). + OPENRAM_VENV="''${OPENRAM_HOME}/.venv" + if [ ! -x "$OPENRAM_VENV/bin/python3" ]; then + echo "OpenRAM: creating venv at $OPENRAM_VENV" + ${pkgs.python3}/bin/python3 -m venv "$OPENRAM_VENV" + fi + export VIRTUAL_ENV="$OPENRAM_VENV" + export PATH="$OPENRAM_VENV/bin:$PATH" + echo "OpenRAM: Nix devShell (venv on PATH: $OPENRAM_VENV)" ''; }; });