Skip to content

Commit f515e71

Browse files
author
ace-pm
committed
chore(nix): run deadnix + statix + alejandra
Automated formatting pass: remove dead bindings, apply statix lint fixes, normalize formatting via alejandra.
1 parent e841ee0 commit f515e71

2 files changed

Lines changed: 88 additions & 87 deletions

File tree

flake.nix

Lines changed: 86 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -6,100 +6,101 @@
66
flake-utils.url = "github:numtide/flake-utils";
77
};
88

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

shell.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
{ pkgs ? import <nixpkgs> {} }:
1+
{pkgs ? import <nixpkgs> {}}:
22
pkgs.mkShell {
33
buildInputs = [
4-
(pkgs.beam.packages.erlang_28.elixir_1_19)
4+
pkgs.beam.packages.erlang_28.elixir_1_19
55
pkgs.beam.packages.erlang_28.erlang
66
];
77
}

0 commit comments

Comments
 (0)