Skip to content

Commit

Permalink
chore: refactor dev shell
Browse files Browse the repository at this point in the history
  • Loading branch information
awwpotato committed Feb 11, 2025
1 parent c74ec19 commit 3340fec
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 115 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ vite.config.ts.timestamp-*

# postgresql
.pg
.dev_postgres
PG_DATA
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ bun db:load

```bash
nix develop
start-database
pg_setup # only first time
pg_start # if you didn't run above command
bun i
bun db:load
echo DATABASE_URL="postgresql://$(whoami):<passwd>@localhost:5432/database?schema=public" >> .env
# once your done
stop-database && exit
pg_stop && exit
```
88 changes: 1 addition & 87 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 29 additions & 25 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
devDB = {
url = "github:hermann-p/nix-postgres-dev-db";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs =
{ nixpkgs, ... }:
let
forAllSystems =
with nixpkgs.lib;
f: genAttrs systems.flakeExposed (system: f nixpkgs.legacyPackages.${system});
in
{
self,
nixpkgs,
utils,
devDB,
systems,
}:
utils.lib.eachSystem (import systems) (
system:
let
pkgs = import nixpkgs { inherit system; };
db = devDB.outputs.packages.${system};
in
{
devShells.default =
devShells = forAllSystems (pkgs: {
default =
with pkgs;
mkShell {
env = {
Expand All @@ -33,17 +22,32 @@
};
buildInputs = [
postgresql_17
db.start-database
db.stop-database
db.psql-wrapped
bun
nodePackages_latest.prettier
openssl
];
shellHook = ''
export PG_ROOT=$(git rev-parse --show-toplevel)
export PG=$PWD/.dev_postgres/
export PGDATA="$PG"data
export PGPORT=5432
export PGHOST=localhost
export PGUSER=$USER
export PGPASSWORD=postgres
export PGDATABASE=example
export DATABASE_URL=postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/$PGDATABASE
alias pg_start="pg_ctl -D $PGDATA -l $PG/postgres.log start"
alias pg_stop="pg_ctl -D $PGDATA stop"
pg_setup() {
pg_stop;
rm -rf $PG;
initdb -D $PGDATA &&
echo "unix_socket_directories = '$PGDATA'" >> $PGDATA/postgresql.conf &&
pg_ctl -D $PGDATA -l $PG/postgres.log start &&
createdb
}
'';
};
}
);
});
};
}

0 comments on commit 3340fec

Please sign in to comment.