A tiny HTTP API that serves quotes - used to demonstrate Flox environments.
This is a simple Go application that serves quotes over HTTP.
Take a look at the code:
cat main.goIt loads quotes from a JSON file and serves them on port 3000.
Let's try to run it:
go run main.go quotes.json
# command not found: goGo is not installed. We need a development environment.
Let's fix that with Flox:
# Create a minimal Flox environment
flox init --bare
# Install Go
flox install go
# Activate the environment
flox activate
# Now it works!
go run main.go quotes.jsonIn another terminal, test it:
curl http://localhost:3000/ | jq
curl http://localhost:3000/quotes | jq
curl http://localhost:3000/quotes/0 | jqOur app can also load quotes from Redis. Let's set that up as a service.
Install Redis:
flox install redisConfigure Redis as a service by editing the manifest:
flox editAdd the following to your manifest.toml:
[services.redis]
command = "redis-server --port $REDISPORT"
[vars]
REDISPORT = "6379"
[profile]
common = """
alias load_quotes='redis-cli -p $REDISPORT SET quotesjson "$(cat quotes.json)"'
"""Now start the services and activate:
flox activate --start-servicesLoad quotes into Redis:
load_quotesRun the app with Redis:
go run main.go redisTest it:
curl http://localhost:3000/quotes | jqInstead of configuring everything ourselves, we can reuse environments from FloxHub. Let's replace our manifest with includes.
Edit the manifest:
flox editReplace the contents with:
version = 1
[install]
[vars]
[include]
environments = [
{ remote = "flox/go" },
{ remote = "flox/redis" }
]That's it! The flox/go environment provides Go, and flox/redis provides
Redis pre-configured as a service.
Reactivate to pick up the changes:
flox activate --start-servicesLoad quotes and run:
redis-cli -p $REDISPORT SET quotesjson "$(cat quotes.json)"
go run main.go redisEnvironment composition lets you build on top of curated, reusable building blocks instead of starting from scratch every time.
Let's package our app for distribution.
Edit the manifest:
flox editAdd a build section:
[build.quotes-app]
command = """
mkdir -p $out/bin $out/share
cp quotes.json $out/share/
go build -trimpath -o $out/bin/quotes-app main.go
"""Build the package:
flox buildTest the built binary:
./result-quotes-app/bin/quotes-app ./result-quotes-app/share/quotes.jsonNow publish it to FloxHub:
flox publishOthers can now use your published package in their environments.
Your app is now available as a reusable package on FloxHub!
Flox integrates with AI coding assistants through MCP (Model Context Protocol).
Install the Flox MCP server (into your default environment):
flox install flox/flox-mcp-serverOr activate it directly:
flox activate -r flox/flox-mcp-serverInstall the Flox plugin in Claude Code:
/plugin marketplace add flox/flox-agentic
/plugin install flox@flox-agenticThe plugin includes 7 specialized skills:
- flox-environments - Package management and environment setup
- flox-services - Service configuration and orchestration
- flox-builds - Building and packaging applications
- flox-containers - Docker/Podman containerization
- flox-publish - Publishing packages to FloxHub
- flox-sharing - Environment composition and collaboration
- flox-cuda - GPU/CUDA development (Linux only)
For Cursor, add to ~/.cursor/mcp.json:
{
"mcpServers": {
"flox": {
"command": "flox-mcp"
}
}
}Now your AI assistant understands Flox! Try asking it to:
- Create a new Flox environment for a Python project
- Add a service to your manifest
- Help debug environment issues
- Build and publish a package
AI + reproducible environments = superpower.
Lab 4 used a manifest build (Bash script). For guaranteed reproducibility, you can use a Nix expression instead.
Create the Nix package file:
mkdir -p .flox/pkgsCreate .flox/pkgs/quotes-app-nix.nix:
{ buildGoModule, lib }:
buildGoModule {
pname = "quotes-app-nix";
version = "1.0.0";
src = ../../.;
vendorHash = null; # Uses go.sum for dependencies
postInstall = ''
mkdir -p $out/share
cp ${../../quotes.json} $out/share/quotes.json
'';
meta = {
description = "A tiny HTTP API that serves quotes";
mainProgram = "quotes-app-go";
};
}Make sure all files are tracked by git:
git add .flox/pkgs/Build with Nix:
flox build .#quotes-app-nixTest the built binary:
./result/bin/quotes-app-go ./result/share/quotes.jsonNote: Package names must be unique. We use quotes-app-nix to avoid conflict
with the manifest build quotes-app from Lab 4.
Why Nix expressions?
- Builds are isolated in a sandbox (no host system leakage)
- Purely functional - same inputs always produce same outputs
- Better for CI/CD and production deployments
- Access to the full Nix ecosystem of build helpers
# Load from a JSON file
go run main.go quotes.json
# Load from Redis
go run main.go redisWhen using Redis as source, populate the data first:
redis-cli SET quotesjson "$(cat quotes.json)"Configure Redis port via environment variable (default: 6379):
REDISPORT=6379 go run main.go redisgo test -v ./...