-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
106 lines (91 loc) · 4.1 KB
/
flake.nix
File metadata and controls
106 lines (91 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
{
description = "singularity_workflow - Elixir implementation of Singularity.Workflow";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
beamPackages = pkgs.beam.packages.erlang;
# Use Elixir 1.19.x (latest)
elixir = beamPackages.elixir_1_19;
# PostgreSQL with pgmq extension
# Note: Using PostgreSQL 18 (uuid_generate_v7() is built-in, no extension needed)
postgresqlWithExtensions = pkgs.postgresql_18.withPackages (ps: [
ps.pgmq # In-database message queue
]);
in {
devShells.default = pkgs.mkShell {
buildInputs = [
beamPackages.erlang
elixir # Elixir 1.19.x
postgresqlWithExtensions
pkgs.nodejs # For moon installation
pkgs.yarn # Alternative package manager
pkgs.gh # GitHub CLI for repository management
];
shellHook = ''
# Clear PATH and rebuild with nix packages FIRST (before system paths)
export PATH="${beamPackages.erlang}/bin:${elixir}/bin:${postgresqlWithExtensions}/bin:${pkgs.nodejs}/bin:${pkgs.yarn}/bin:${pkgs.gh}/bin:$PATH"
export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/singularity_workflow"
echo "ShellHook PATH: $PATH"
echo "Elixir location: $(which elixir 2>/dev/null || echo 'not found')"
echo "Mix location: $(which mix 2>/dev/null || echo 'not found')"
echo "GitHub CLI location: $(which gh 2>/dev/null || echo 'not found')"
# Install moon if not present
if ! command -v moon >/dev/null 2>&1; then
echo "Moon task runner not available - using mix commands directly"
fi
# Function to cleanup PostgreSQL on exit
cleanup_postgres() {
if [ -f ".postgres_pid" ] && kill -0 $(cat .postgres_pid) 2>/dev/null; then
echo "Stopping PostgreSQL..."
pg_ctl -D .postgres_data stop
rm -f .postgres_pid
fi
}
# Set trap to cleanup on shell exit
trap cleanup_postgres EXIT
# Start PostgreSQL if not already running
if ! pg_isready -h localhost -p 5432 >/dev/null 2>&1; then
echo "Starting PostgreSQL..."
# Create data directory if it doesn't exist
if [ ! -d ".postgres_data" ]; then
echo "Initializing PostgreSQL data directory..."
initdb -D .postgres_data --no-locale --encoding=UTF8
fi
# Start PostgreSQL
pg_ctl -D .postgres_data -l .postgres.log -o "-p 5432" start
echo $! > .postgres_pid
# Wait for PostgreSQL to be ready
sleep 3
# Create postgres role if it doesn't exist
if ! psql -p 5432 -d postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='postgres'" | grep -q 1; then
echo "Creating postgres role..."
psql -p 5432 -d postgres -c "CREATE ROLE postgres WITH SUPERUSER LOGIN PASSWORD 'postgres';"
fi
# Create database and install extensions if they don't exist
if ! psql -lqt | cut -d \| -f 1 | grep -qw singularity_workflow; then
echo "Creating singularity_workflow database..."
createdb -p 5432 singularity_workflow
psql -p 5432 -d singularity_workflow -c "CREATE EXTENSION IF NOT EXISTS pgmq;"
echo "Database and extensions ready"
else
echo "Database already exists"
fi
echo "PostgreSQL started with pgmq extension"
else
echo "PostgreSQL already running"
fi
echo "singularity_workflow development environment ready!"
echo "Database: singularity_workflow on localhost:5432 with pgmq extension"
echo "Run 'mix test' to run tests"
echo "PostgreSQL will auto-stop when you exit this shell"
'';
};
});
}