Created
January 24, 2025 01:58
-
-
Save maikelthedev/1b38fb752e20abab5d8ed963f880b3c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs ? import <nixpkgs> {} }: | |
pkgs.mkShell { | |
name = "indie"; | |
nativeBuildInputs = with pkgs; [ | |
elixir_1_18 | |
erlang | |
rebar3 | |
nodejs | |
yarn | |
fish | |
gnumake | |
postgresql | |
]; | |
# Hook to automatically switch to Fish when entering the shell | |
shellHook = '' | |
export MIX_ENV=dev | |
export NIX_ENFORCE_PURITY=0 # Without this bcrypt does not compile | |
redecho() { echo -e "\e[31m$1\e[0m"; } | |
greenecho() { echo -e "\e[32m$1\e[0m"; } | |
# Define the path for the .iex.exs file | |
IEX_FILE="$PWD/.iex.exs" | |
# Create the .iex.exs file if it doesn't exist | |
if [ ! -f "$IEX_FILE" ]; then | |
redecho "Creating .iex.exs file with aliases and auto_reload" | |
cat <<EOF > "$IEX_FILE" | |
IEx.configure(auto_reload: true) | |
alias Indie.Repo | |
alias Indie.Accounts.{User, Address} | |
alias Indie.Commerce.Order | |
alias Indie.Domains.Domain | |
EOF | |
fi | |
# Print a message indicating the .iex.exs file is ready | |
[ -f "$IEX_FILE" ] && greenecho "iex.exs file is ready!" | |
# Run mix deps.get and mix deps.compile if necessary | |
[ ! -d "deps" ] && redecho "Running mix deps.get" && mix deps.get | |
[ ! -d "_build" ] && redecho "Running mix deps.compile" && mix deps.compile | |
# Do some fancy PostgresSQL commands | |
#[ ! -d ".data" ] && redecho "Creating database" && initdb -D .data | |
# Define project folder and custom directories | |
export PROJECT_DIR=/tmp/indie | |
export PGDATA="$PROJECT_DIR/data" | |
export PGLOG="$PROJECT_DIR/logfile" | |
export PGPORT=5433 | |
export PGLockDir="$PROJECT_DIR/.lock" | |
alias quit="killall -s KILL postgres && exit" | |
# Ensure the custom directories exist | |
rm -r $PGDATA | |
mkdir -p $PGDATA | |
mkdir -p $PGLockDir | |
chmod 700 $PGDATA | |
chmod 700 $PGLockDir | |
# Run PostgreSQL with custom socket directory | |
pg_ctl initdb -o "-U postgres" | |
pg_ctl -D $PGDATA -l $PGLOG -o "-p $PGPORT -h localhost -k $PGLockDir" start | |
trap 'killall -s KILL postgres' EXIT | |
# Create the database | |
sleep 2 && mix ecto.create && mix ecto.reset | |
# Switch to fish shell if not already in fish | |
#exec ${pkgs.fish}/bin/fish | |
''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment