# Use the Nix development shell

Source: https://zotonic.com/docs/3046/use-the-nix-development-shell

URI: https://zotonic.com/id/3046

Language: en

Enter the supplied OTP 28 development shell, prepare PostgreSQL, and build.

Use this route if you already work with Nix. Start from the checkout in [Set up a local development environment](/id/1526). Install Nix using its [official installation instructions](https://nixos.org/download/) if needed.

1. Enter the supplied shell
---------------------------

From the repository root:

```sh
nix-shell
```

Wait for dependencies to finish downloading or building. The checked-in `shell.nix` selects `erlang_28` and includes PostgreSQL tools and the platform's file watcher. Keep this shell open for all build and Zotonic commands.

Check the runtime:

```sh
erl -noshell -eval 'io:format("~s~n", [erlang:system_info(otp_release)]), halt().'
```

Expect `28`.

2. Start a local database
-------------------------

The shell supplies PostgreSQL programs; it does not start a database server. If you already have a local server, follow [Prepare local PostgreSQL](/id/3045).

Otherwise, create a new development cluster in the checkout, as your normal user:

```sh
initdb -D .local-postgres --auth-local=peer --auth-host=scram-sha-256
pg_ctl -D .local-postgres -l .local-postgres/server.log -o "-h localhost -p 5432 -k $(pwd)/.local-postgres" start
```

Add `.local-postgres/` to `.git/info/exclude` so database files stay out of Git. Use an empty directory for `initdb`. If port 5432 is already occupied, use the existing local server or configure a different port throughout.

Local peer authentication uses your operating-system username. Open `psql -h "$(pwd)/.local-postgres" postgres` as that same user and follow the SQL in [Prepare local PostgreSQL](/id/3045).

3. Build and try a site
-----------------------

Follow [Build and start Zotonic](/id/2913) and [Create your first site](/id/2914) inside the Nix shell. If you open another terminal for Zotonic commands, enter `nix-shell` there too.

When finished, stop Zotonic with `bin/zotonic stop`. If you started the cluster above, stop it with `pg_ctl -D .local-postgres stop` before leaving the shell. Keep the directory to reuse its data next time.

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/3046?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/3046?language=en>)
