Created
May 5, 2025 04:41
-
-
Save Sammyalhashe/5d8a032a63ae74ae8bbcda5978ef08cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
description = "Dev-environment flake"; | |
inputs = { | |
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; | |
systems.url = "github:nix-systems/default"; | |
devenv.url = "github:cachix/devenv"; | |
}; | |
outputs = { self, nixpkgs, devenv, systems, ... }@inputs: | |
let forEachSystem = nixpkgs.lib.genAttrs (import systems); | |
in | |
{ | |
packages = forEachSystem (system: | |
let pkgs = nixpkgs.legacyPackages.${system}; | |
in | |
{ | |
insomnia = pkgs.insomnia; | |
devenv-up = self.devShells.${system}.default.config.procfileScript; | |
devenv-test = self.devShells.${system}.default.config.test; | |
} | |
); | |
devShells = forEachSystem (system: | |
let pkgs = nixpkgs.legacyPackages.${system}; | |
in | |
{ | |
default = devenv.lib.mkShell { | |
inherit inputs pkgs; | |
modules = [{ | |
packages = with pkgs; [ | |
bash-language-server | |
docker | |
hello | |
python312Packages.python-lsp-server | |
python313 | |
python313Packages.uv | |
]; | |
enterShell = '' | |
hello --greeting="Happy Hacking :)" | |
''; | |
enterTest = '' | |
pytest | |
''; | |
env = { | |
DATABASE_URL = "postgresql://localhost:5432/receiptsdb"; | |
}; | |
services.postgres = { | |
enable = true; | |
package = pkgs.postgresql_15; | |
initialDatabases = [ { name = "receiptsdb"; } ]; | |
listen_addresses = "127.0.0.1"; | |
initialScript = '' | |
CREATE USER postgres SUPERUSER; | |
ALTER USER postgres PASSWORD 'postgres'; | |
GRANT ALL PRIVILEGES ON DATABASE receiptsdb to admin; | |
''; | |
}; | |
scripts.start_processes.exec = '' | |
devenv up -D | |
''; | |
scripts.stop_processes.exec = '' | |
process-compose down | |
''; | |
scripts.attach_processes.exec = '' | |
process-compose attach | |
''; | |
scripts.insomnia.exec = '' | |
nix run .#insomnia >/dev/null 2>&1 & | |
''; | |
scripts.ping_postgres.exec = '' | |
# Wait for PostgreSQL to be ready | |
echo "⏳ Waiting for Postgres to be ready..." | |
until pg_isready -d receiptsdb -p 5432 -U postgres; do | |
sleep 1 | |
done | |
echo "✅ Postgres is up! Running SQLModel database initialization..." | |
''; | |
scripts.setup_db.exec = '' | |
uv run ./dev/setup_db.py | |
''; | |
scripts.start_app.exec = '' | |
uv run fastapi dev --host 0.0.0.0 --port 8000 | |
''; | |
}]; | |
}; | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment