# Nix Flakes Support

This section should be added to the main README.md under the "Development Setup" section.

---

## Development Setup

### Option 1: Nix Flakes (Recommended)

Towerops uses Nix flakes for reproducible development environments and builds.

**Prerequisites:**
- [Nix](https://nixos.org/) with flakes enabled
- [direnv](https://direnv.net/) (optional but recommended)

**Quick Start:**

```bash
# Clone the repository
git clone <repository-url>
cd towerops-web

# Option A: Using direnv (automatic environment)
cp .envrc.example .envrc
direnv allow

# Option B: Manual Nix shell
nix develop
```

The development environment includes:
- Elixir 1.19.5 / OTP 28.3
- PostgreSQL 16 (auto-started)
- Redis (auto-started)
- All development tools (LSPs, formatters, etc.)

**Start the Phoenix server:**

```bash
mix phx.server
# Visit http://localhost:4000
```

**Available Commands:**

```bash
mix phx.server       # Start Phoenix development server
mix test             # Run test suite
mix precommit        # Run pre-commit checks (format, credo, test)
start-services       # Start PostgreSQL and Redis
stop-services        # Stop PostgreSQL and Redis
```

**Building Docker Images:**

```bash
# Build production Docker image
nix build .#dockerImage

# Load into Docker
docker load < result

# Run the container
docker run --rm -p 4000:4000 \
  -e DATABASE_URL="..." \
  -e SECRET_KEY_BASE="..." \
  registry.gitlab.com/towerops/towerops:latest
```

**See [docs/nix.md](docs/nix.md) for comprehensive Nix documentation.**

### Option 2: Traditional Setup

If you prefer not to use Nix, follow the traditional setup:

**Prerequisites:**
- Elixir 1.19.5 / OTP 28.3 (via [asdf](https://asdf-vm.com/))
- PostgreSQL 14+ (with TimescaleDB for production)
- Redis
- net-snmp development libraries

**macOS:**

```bash
brew install asdf postgresql@16 redis net-snmp
asdf plugin-add erlang
asdf plugin-add elixir
asdf install
brew services start postgresql@16
brew services start redis
```

**Linux (Ubuntu/Debian):**

```bash
# Install asdf
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.13.1

# Install dependencies
sudo apt-get update
sudo apt-get install build-essential autoconf m4 libncurses5-dev \
  libwxgtk3.0-gtk3-dev libgl1-mesa-dev libglu1-mesa-dev libpng-dev \
  libssh-dev unixodbc-dev xsltproc fop libxml2-utils libncurses-dev \
  postgresql-16 redis-server libsnmp-dev

# Install Elixir/Erlang
asdf plugin-add erlang
asdf plugin-add elixir
asdf install

# Start services
sudo systemctl start postgresql
sudo systemctl start redis
```

**Setup:**

```bash
# Install dependencies
mix deps.get

# Create and migrate database
mix ecto.setup

# Build assets
mix assets.build

# Start Phoenix server
mix phx.server
```

---

Add this section to README.md after cloning the template.
