refactor: clean up flake.nix and nixos configurations for improved readability and organization

- Reformatted `flake.nix` for better structure and consistency, including adjustments to package lists and added metadata for applications.
- Updated `nixos/gitea-runner.nix` to streamline configuration and improve clarity.
- Refined `nixos/tests.nix` by consolidating service definitions and enhancing test scripts for better maintainability and readability.
This commit is contained in:
Danilo Reyes
2025-11-02 00:42:46 -06:00
parent d40139822d
commit 07f4ea8277
3 changed files with 241 additions and 181 deletions

136
flake.nix
View File

@@ -6,37 +6,41 @@
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
outputs =
{ self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
pythonEnv = pkgs.python3.withPackages (ps: with ps; [
# Core backend dependencies
fastapi
uvicorn
sqlalchemy
alembic
pydantic
pydantic-settings # Settings management
psycopg2 # PostgreSQL driver
# Auth & Security
python-jose
passlib
bcrypt # Password hashing backend for passlib
email-validator # Email validation for pydantic
# Image processing
pillow
# Storage
boto3
# HTTP & uploads
httpx
python-multipart
# Testing
pytest
pytest-cov
pytest-asyncio
]);
pythonEnv = pkgs.python3.withPackages (
ps: with ps; [
# Core backend dependencies
fastapi
uvicorn
sqlalchemy
alembic
pydantic
pydantic-settings # Settings management
psycopg2 # PostgreSQL driver
# Auth & Security
python-jose
passlib
bcrypt # Password hashing backend for passlib
email-validator # Email validation for pydantic
# Image processing
pillow
# Storage
boto3
# HTTP & uploads
httpx
python-multipart
# Testing
pytest
pytest-cov
pytest-asyncio
]
);
in
{
devShells.default = pkgs.mkShell {
@@ -45,25 +49,25 @@
pythonEnv
uv
ruff
# Database
postgresql
# Frontend
nodejs
nodePackages.npm
# Image processing
imagemagick
# Storage
minio
minio-client
# Development tools
git
direnv
# Optional: monitoring/debugging
# redis
];
@@ -89,7 +93,7 @@
echo " App: http://localhost:5173"
echo " MinIO UI: http://localhost:9001"
echo ""
# Set up environment variables
export DATABASE_URL="postgresql://localhost/webref"
export PYTHONPATH="$PWD/backend:$PYTHONPATH"
@@ -98,12 +102,24 @@
# Apps - Scripts that can be run with `nix run`
apps = {
default = {
type = "app";
program = "${pkgs.writeShellScript "help" ''
echo "Available commands:"
echo " nix run .#lint - Run linting checks"
echo " nix run .#lint-fix - Auto-fix linting issues"
''}";
meta = {
description = "Show available commands";
};
};
# Unified linting for all code
lint = {
type = "app";
program = "${pkgs.writeShellScript "lint" ''
set -e
# Backend Python linting
echo "🔍 Linting backend Python code..."
if [ -d "backend" ]; then
@@ -115,7 +131,7 @@
echo " Not in project root (backend/ not found)"
exit 1
fi
# Frontend linting (if node_modules exists)
if [ -d "frontend/node_modules" ]; then
echo ""
@@ -128,18 +144,21 @@
else
echo " Frontend node_modules not found, run 'npm install' first"
fi
echo ""
echo " All linting checks passed!"
''}";
meta = {
description = "Run linting checks on backend and frontend code";
};
};
# Auto-fix linting issues
lint-fix = {
type = "app";
program = "${pkgs.writeShellScript "lint-fix" ''
set -e
echo "🔧 Auto-fixing backend Python code..."
if [ -d "backend" ]; then
cd backend
@@ -150,7 +169,7 @@
echo " Not in project root (backend/ not found)"
exit 1
fi
if [ -d "frontend/node_modules" ]; then
echo ""
echo "🔧 Auto-fixing frontend code..."
@@ -158,33 +177,52 @@
${pkgs.nodePackages.prettier}/bin/prettier --write src/
cd ..
fi
echo ""
echo " Auto-fix complete!"
''}";
meta = {
description = "Auto-fix linting issues in backend and frontend code";
};
};
};
# Package definitions (for production deployment)
packages = {
packages = rec {
# Backend package
backend = pkgs.python3Packages.buildPythonApplication {
pname = "webref-backend";
version = "1.0.0";
pyproject = true;
src = ./backend;
build-system = with pkgs.python3Packages; [
setuptools
];
propagatedBuildInputs = with pkgs.python3Packages; [
fastapi
uvicorn
sqlalchemy
alembic
pydantic
pydantic-settings
psycopg2
python-jose
passlib
pillow
boto3
httpx
python-multipart
email-validator
bcrypt
];
meta = {
description = "Reference Board Viewer - Backend API";
homepage = "https://github.com/yourusername/webref";
license = pkgs.lib.licenses.mit;
};
};
# Frontend package
@@ -192,7 +230,7 @@
pname = "webref-frontend";
version = "1.0.0";
src = ./frontend;
npmDepsHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; # Update after first build
npmDepsHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; # Update after first build
buildPhase = ''
npm run build
'';
@@ -200,7 +238,14 @@
mkdir -p $out
cp -r build/* $out/
'';
meta = {
description = "Reference Board Viewer - Frontend SPA";
homepage = "https://github.com/yourusername/webref";
license = pkgs.lib.licenses.mit;
};
};
default = backend;
};
# NixOS VM tests
@@ -208,4 +253,3 @@
}
);
}