Nix Deployment
Nixi integrates seamlessly with Nix for reproducible, declarative deployments. This guide covers nix run, nix build, and Flakes.
Quick Start with Nix
Clone the repository and enter the development environment:
# Clone and run
git clone https://github.com/ijadux2/nixi.git
cd nixi
# Enter development environment (recommended)
nix develop .
# Start the server
lua server.lua
# Or with live reload
lua server.lua --watch
Using shell.nix (Legacy)
The project includes a shell.nix for traditional Nix users:
# Enter development environment
nix-shell
# Or with custom path
nix-shell shell.nix
# Then run the server
lua server.lua
Shell Features
The development shell includes:
- Lua 5.4 with LuaJIT
- LuaSocket (HTTP server)
- LuaFileSystem (file-based routing)
- dkjson (JSON encoding)
- busted (testing framework)
- Automatic Lua path configuration
Flake Integration
For modern Nix with flakes enabled, use flake.nix:
# Enter development shell
nix develop .
# Or specific shell
nix develop .#default
nix develop .#minimal
# Build the project
nix build
# Run the built binary
./result/bin/nixi
Available Shells
| Shell | Description |
|---|---|
default | Full development environment with all dependencies |
minimal | Minimal shell with only Lua + LuaSocket + LuaFileSystem |
Adding to Your Project
Reference Nixi in your project's flake:
{
inputs.nixi.url = "github:ijadux2/nixi";
outputs = { self, nixpkgs, nixi }: {
devShells.x86_64-linux.default = nixpkgs.legacyPackages.x86_64-linux.mkShell {
buildInputs = with nixpkgs.legacyPackages.x86_64-linux; [
lua5_4
(lua5_4.withPackages (ps: with ps; [
luafilesystem
luasocket
dkjson
]))
nixi.packages.x86_64-linux.default
];
};
};
}
Environment Variables
| Variable | Default | Description |
|---|---|---|
NIXI_HOST | 0.0.0.0 | Server bind address |
NIXI_PORT | 3000 | Server port |
NIXI_ENV | production | Environment mode |
Building for Production
# Build the project
nix build
# The binary is at ./result/bin/nixi
./result/bin/nixi new myapp
cd myapp
# Set environment
export NIXI_HOST=0.0.0.0
export NIXI_PORT=3000
# Run
lua server.lua