build(nix): unify Python dev environment via .venv symlink and add pyright to scripts/test

- Extract shared pythonEnv in flake.nix and symlink .venv in devShell
  shellHook so IDEs, terminal, and Nix checks share one Python 3.14 env.
- Add pyright static type checking to scripts/test and align pre-commit
  with the unified Nix environment.
- Remove personal domain from flake.nix description and ignore .venv.
This commit is contained in:
kiskaadee committed 2026-10-15 19:27:30 -05:00
1 parent 2bf0635ba9
commit 61a2798d4f
4 files changed
+33 -23

No files matched your search

+7 -9
View File
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
set -e
set -euo pipefail
# ==============================================================================
# Homelab Core Pre-Commit Invariant & Quality Gate Hook
# Runs linter (Ruff) and architecture & security test suite (Pytest)
# Runs linter (Ruff), static type checker (Pyright), and test suite (Pytest)
# ==============================================================================
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
@@ -13,26 +13,24 @@ echo "🔍 [pre-commit] Executing Homelab Core invariant checks..."
# 1. Run Ruff Linter
echo " ↳ Linting repository with Ruff..."
if command -v uv >/dev/null 2>&1; then
uv run ruff check .
elif command -v ruff >/dev/null 2>&1; then
if command -v ruff >/dev/null 2>&1; then
ruff check .
elif command -v nix >/dev/null 2>&1 && [ -f flake.nix ]; then
nix develop --command ruff check .
else
echo "⚠️ [pre-commit] Neither uv, ruff, nor nix found; skipping ruff"
echo "⚠️ [pre-commit] Neither ruff nor nix found; skipping ruff"
fi
# 2. Run Pytest Suite
echo " ↳ Running structural and security test suite with Pytest..."
if command -v uv >/dev/null 2>&1; then
uv run --with pytest --with pyyaml pytest tests/
if [ -x ".venv/bin/pytest" ]; then
.venv/bin/pytest tests/
elif command -v pytest >/dev/null 2>&1; then
pytest tests/
elif command -v nix >/dev/null 2>&1 && [ -f flake.nix ]; then
nix develop --command pytest tests/
else
echo "⚠️ [pre-commit] Neither uv, pytest, nor nix found; skipping pytest"
echo "⚠️ [pre-commit] Neither pytest nor nix found; skipping pytest"
fi
echo "✅ [pre-commit] All repository checks passed successfully!"
+1
View File
@@ -5,6 +5,7 @@ secrets.txt
backup.zip
.envrc
.direnv
.venv
# SSL / ACME Certificates & Keys
config/letsencrypt/*
+13 -11
View File
@@ -1,5 +1,5 @@
{
description = "Homelab Core — Turnkey Declarative NixOS Appliance for roadtotech.me";
description = "Homelab Core — Turnkey Declarative NixOS Appliance";
inputs = {
nixpkgs.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.zst";
@@ -14,6 +14,12 @@
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
pythonEnv = pkgs.python3.withPackages (ps: with ps; [
pyyaml
types-pyyaml
pytest
pydantic
]);
in
{
nixosConfigurations.server = nixpkgs.lib.nixosSystem {
@@ -27,17 +33,16 @@
devShells.${system}.default = pkgs.mkShell {
buildInputs = with pkgs; [
(python3.withPackages (ps: with ps; [
pyyaml
types-pyyaml
pytest
pydantic
]))
pythonEnv
pyright
ruff
];
shellHook = ''
git config core.hooksPath .githooks 2>/dev/null || true
if [ -d .venv ] && [ ! -L .venv ]; then
rm -rf .venv
fi
ln -sfn ${pythonEnv} .venv
'';
};
@@ -45,10 +50,7 @@
test-suite = pkgs.runCommand "core-tests" {
nativeBuildInputs = with pkgs; [
git
python3
python3Packages.pytest
python3Packages.pyyaml
python3Packages.pydantic
pythonEnv
ruff
];
} ''
+12 -3
View File
@@ -8,14 +8,23 @@ echo "🔍 Running code linters (ruff)..."
if command -v ruff &>/dev/null; then
ruff check .
else
nix-shell -p ruff --run "ruff check ."
nix develop --command ruff check .
fi
echo "🔎 Running static type analysis (pyright)..."
if command -v pyright &>/dev/null; then
pyright
else
nix develop --command pyright
fi
echo "🧪 Running architecture & security test suite (pytest)..."
if command -v pytest &>/dev/null; then
if [ -x ".venv/bin/pytest" ]; then
.venv/bin/pytest tests/
elif command -v pytest &>/dev/null; then
pytest tests/
else
nix-shell -p python3Packages.pytest python3Packages.pyyaml python3Packages.pydantic --run "pytest tests/"
nix develop --command pytest tests/
fi
echo "❄️ Verifying NixOS flake & sandbox checks..."