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