Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow developers to use nix-shell to get started #554

Merged
merged 13 commits into from
Feb 23, 2024
31 changes: 31 additions & 0 deletions .github/workflows/nix-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test nix-shell

on:
push:
branches:
- '*'

jobs:
nix-shell:
strategy:
matrix:
os: [ macos-latest, ubuntu-latest ]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
with:
# Fetch the whole history for all tags and branches (required for aleph.__version__)
fetch-depth: 0

- name: Setup empty config file
run: touch config.yml

- name: Set up Nix
uses: cachix/install-nix-action@v25
with:
# Use channel nixos-23.11 for Linux and nixpkgs-23.11-darwin for macOS
nix_path: nixpkgs=channel:${{ matrix.os == 'macos-latest' && 'nixpkgs-23.11-darwin' || 'nixos-23.11' }}

- name: Run tests
run: nix-shell --run "pytest"
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ pip install -e .[testing,docs]

You're ready to go!

### Developer setup using Nix

We started to add Nix as an easy way to setup a development environment.
This is still a work in progress and not all dependencies are covered yet.

To use it, you need to [have Nix installed on your system](https://nixos.org/download.html). Then you can run:

```bash
nix-shell
```
This will provide you with a shell with PostgreSQL, Redis, and IPFS running.

## Software used

The Aleph CCN is written in Python and requires Python v3.8+. It will not work with older versions of Python.
Expand Down
69 changes: 69 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
buildInputs = [
pkgs.postgresql
pkgs.redis
pkgs.kubo

pkgs.python311
pkgs.python311Packages.virtualenv
pkgs.python311Packages.pip
pkgs.python311Packages.setuptools

pkgs.python311Packages.secp256k1
pkgs.python311Packages.fastecdsa
pkgs.python311Packages.greenlet
];

shellHook = ''
echo "Setting up PostgreSQL environment..."
export PGDATA=$(mktemp -d)
PG_SOCKET_DIR=$(mktemp -d)
echo "Initializing database..."
initdb $PGDATA

echo "Starting PostgreSQL with custom socket directory..."
pg_ctl -D $PGDATA -o "-k $PG_SOCKET_DIR" -l logfile start

# Wait a bit for the server to start
sleep 1

# Create the 'aleph' role and a database
createuser -h $PG_SOCKET_DIR aleph
createdb -h $PG_SOCKET_DIR aleph -O aleph

# Create a temporary directory for Redis
export REDIS_DATA_DIR=$(mktemp -d)
redis-server --daemonize yes --dir $REDIS_DATA_DIR --bind 127.0.0.1 --port 6379
echo "Redis server started. Data directory is $REDIS_DATA_DIR"