diff --git a/.gitignore b/.gitignore index 2f3b58c0..ceb436fe 100755 --- a/.gitignore +++ b/.gitignore @@ -47,4 +47,7 @@ next-env.d.ts uploads*/ *.crt *.key -generated \ No newline at end of file +generated + +# nix dev env +/.psql_db/ \ No newline at end of file diff --git a/README.md b/README.md index d049bb38..344c51a2 100755 --- a/README.md +++ b/README.md @@ -198,6 +198,24 @@ Create a pull request on GitHub. If your PR does not pass the action checks, the Here's how to setup Zipline for development +#### Nix + +If you have [Nix](https://nixos.org/) installed, you can use the provided dev shell to get started quickly. Just run: + +```bash +nix develop +``` + +This will start a postgres server, and drop you into a shell with the necessary tools installed: + +- nodejs +- corepack +- git +- ffmpeg +- postgres server + +After hopping into the dev shell, you can follow the instructions below (skipping the prerequisites) to setup a configuration and start the server. + #### Prerequisites - nodejs (lts -> 20.x, 22.x) diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..69cf111f --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-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" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1752827260, + "narHash": "sha256-noFjJbm/uWRcd2Lotr7ovedfhKVZT+LeJs9rU416lKQ=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "b527e89270879aaaf584c41f26b2796be634bc9d", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "rev": "b527e89270879aaaf584c41f26b2796be634bc9d", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..96184982 --- /dev/null +++ b/flake.nix @@ -0,0 +1,84 @@ +{ + description = "dev env for zipline"; + + inputs = { + # node 24.4.1, postgres 17 + nixpkgs.url = "github:nixos/nixpkgs/b527e89270879aaaf584c41f26b2796be634bc9d"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = + { + self, + nixpkgs, + flake-utils, + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { + inherit system; + }; + + nodejs = pkgs.nodejs_24; + postgres = pkgs.postgresql; + psqlDir = ".psql_db/data"; + + psqlUsername = "postgres"; + psqlPassword = "postgres"; + in + { + devShells.default = pkgs.mkShell { + name = "zipline-dev"; + + buildInputs = [ + nodejs + postgres + + pkgs.git + pkgs.corepack + pkgs.ffmpeg + ]; + + shellHook = '' + export PGDATA="$PWD/${psqlDir}" + export PGUSER="${psqlUsername}" + export PGPASSWORD="${psqlPassword}" + export PGPORT=5432 + + if [ ! -d "$PGDATA" ]; then + echo "Initializing PostgreSQL data directory at $PGDATA" + initdb -D "$PGDATA" --username="$PGUSER" --pwfile=<(echo "$PGPASSWORD") + fi + + # listen on localhost + echo "host all all 127.0.0.1/32 password" >> "$PGDATA/pg_hba.conf" + echo "host all all ::1/128 password" >> "$PGDATA/pg_hba.conf" + sed -i "s/^#\?listen_addresses.*/listen_addresses = 'localhost'/" "$PGDATA/postgresql.conf" + + echo "Starting PostgreSQL..." + pg_ctl -D "$PGDATA" -o "-p $PGPORT" -w start + + echo -e "PostgreSQL is ready at postgresql://$PGUSER:$PGPASSWORD@localhost:$PGPORT/postgres\n\n" + + stop_postgres() { + echo "Stopping PostgreSQL..." + pg_ctl -D "$PGDATA" stop + } + + # trap pg to stop on exiting the dev shell + trap stop_postgres EXIT + + # use zsh if zsh is available + if command -v zsh >/dev/null 2>&1; then + zsh + else + $SHELL + fi + + exit + ''; + }; + } + ); +}