shellHook now derives PGDATA from $(git rev-parse --show-toplevel) instead of $PWD. nix develop / direnv from a subdir (e.g. backend/) used to seed a duplicate cluster at backend/.postgres that leaked into git tracking. .gitignore loses its leading slash on .postgres/ + .direnv/ + .pc.* so any nested cluster also gets ignored. fallback to pwd preserves behavior outside a git repo. 968 stray backend/.postgres/* blobs already pruned from history via git-filter-repo before this commit.
52 lines
1.6 KiB
Nix
52 lines
1.6 KiB
Nix
{
|
|
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 = ''
|
|
# Anchor PGDATA to the repo root so subshells in subdirs
|
|
# (e.g. backend/) reuse the same cluster instead of seeding
|
|
# a stray .postgres there.
|
|
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
|
|
export PGDATA="$REPO_ROOT/.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"
|
|
'';
|
|
};
|
|
});
|
|
}
|