diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..5c22d71 --- /dev/null +++ b/.envrc @@ -0,0 +1,10 @@ +# Load the flake environment +use flake + +# Use PHP and Node layouts +layout php +layout node + +# Watch for dependency changes +watch_file composer.json +watch_file package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e3b9d87 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# Nix devshell artefacts +/.postgres/ +/.direnv/ +result +result-* + +# Process-compose state +/.pc.* +process-compose-*.log diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ca6617a --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1777954456, + "narHash": "sha256-hGdgeU2Nk87RAuZyYjyDjFL6LK7dAZN5RE9+hrDTkDU=", + "owner": "NixOs", + "repo": "nixpkgs", + "rev": "549bd84d6279f9852cae6225e372cc67fb91a4c1", + "type": "github" + }, + "original": { + "owner": "NixOs", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6725942 --- /dev/null +++ b/flake.nix @@ -0,0 +1,48 @@ +{ + inputs = { + nixpkgs.url = "github:NixOs/nixpkgs/nixos-unstable"; + utils.url = "github:numtide/flake-utils"; + }; + outputs = { self, nixpkgs, utils }: + utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in { + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [ + onefetch + php + phpPackages.composer + phpPackages.php-codesniffer + vscode-langservers-extracted + sqlite + nodejs + nixfmt-rfc-style + nixfmt-tree + cypress + yaml-language-server + typescript + postgresql + process-compose + ]; + + shellHook = '' + export PGDATA="$PWD/.postgres" + export PGHOST="$PGDATA" + export PGUSER="postgres" + export PGDATABASE="postgres" + + if [ ! -d "$PGDATA" ]; then + echo "[pg] initializing cluster at $PGDATA" + initdb --auth=trust --username=postgres --no-locale --encoding=UTF8 >/dev/null + { + echo "listen_addresses = '127.0.0.1'" + echo "unix_socket_directories = '$PGDATA'" + } >> "$PGDATA/postgresql.conf" + fi + + echo "[dev] run 'process-compose up' to start postgres + backend + vite" + ''; + }; + }); +} diff --git a/process-compose.yaml b/process-compose.yaml new file mode 100644 index 0000000..f4b785f --- /dev/null +++ b/process-compose.yaml @@ -0,0 +1,37 @@ +version: "0.5" + +processes: + postgres: + command: postgres -D "$PGDATA" -k "$PGDATA" -c listen_addresses=127.0.0.1 + shutdown: + signal: 2 + readiness_probe: + exec: + command: pg_isready -h "$PGDATA" + initial_delay_seconds: 1 + period_seconds: 2 + + backend: + command: php artisan serve --host=127.0.0.1 --port=8000 + working_dir: ./backend + depends_on: + postgres: + condition: process_healthy + readiness_probe: + http_get: + host: 127.0.0.1 + port: 8000 + path: /up + initial_delay_seconds: 2 + period_seconds: 10 + + vite: + command: npm run dev + working_dir: ./frontend/blog_portal + readiness_probe: + http_get: + host: 127.0.0.1 + port: 5173 + path: / + initial_delay_seconds: 2 + period_seconds: 2