← Back to Course Index

Lesson 8: Capstone Project

Build and share a complete reproducible environment

Learning Objectives

Your Mission

Choose a real project (existing or new) and create a complete, reproducible Nix development environment for it. Document it clearly. Make it so a teammate can clone your repo and have a working dev environment in minutes.

Project Ideas

Pick one that matches your interests:

Capstone Checklist

  • Create a flake.nix with all required dependencies
  • Test the environment locally (nix develop)
  • Create a README explaining the project and Nix setup
  • Commit flake.nix and flake.lock to git
  • Test reproducibility: Clone to a fresh directory and verify it works
  • Document any gotchas (special setup steps, environment variables)
  • Optional: Add a shellHook with helpful developer notes
  • Step-by-Step Guide

    Step 1: Understand Your Project's Dependencies

    Before writing flake.nix, list exactly what your project needs:

    # Example for a Python project: # - Python 3.11 # - Poetry (package manager) # - PostgreSQL (for dev database) # - Redis (for cache) # - Git (probably already have it)

    Check your project's documentation, requirements files, etc.

    Step 2: Write Your flake.nix

    Start with a template and customize it:

    { description = "My Project - Dev Environment"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; flake-utils.url = "github:numtide/flake-utils"; }; outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; in { devShells.default = pkgs.mkShell { buildInputs = with pkgs; [ # Add your dependencies here ]; shellHook = '' echo "Development environment for My Project loaded!" ''; }; } ); }

    Step 3: Test Your Environment

    Initialize the flake:
    nix flake update
    Enter the environment:
    nix develop
    Verify your tools work:
    # Run commands that your project needs python --version poetry --version # etc.
    Try building/running your project:
    # Whatever your project needs: npm install && npm start # or poetry install && poetry run python app.py # or cargo build

    Step 4: Document Your Setup

    Create a clear README section for developers:

    ## Development Setup This project uses Nix for reproducible development environments. ### Quick Start ```bash # Enter the dev environment nix develop # (Inside the environment) poetry install npm install # etc. ``` ### What's Included - Python 3.11 - Poetry - PostgreSQL - Redis ### Troubleshooting If something doesn't work: 1. Ensure you have Nix installed 2. Run `nix flake update` 3. Exit and re-enter: `exit` then `nix develop`

    Step 5: Commit and Test

    Add files to git:
    git add flake.nix flake.lock README.md git commit -m "Add Nix development environment"
    Test reproducibility (simulate a new developer):
    cd /tmp git clone /path/to/your/project cd project nix develop # Verify everything works
    Push to GitHub/GitLab (if you have a repo):
    git push origin main

    Real-World Example: Full Stack Node App

    { description = "Full stack Node.js + PostgreSQL app"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; flake-utils.url = "github:numtide/flake-utils"; }; outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; in { devShells.default = pkgs.mkShell { buildInputs = with pkgs; [ nodejs_20 postgresql redis git ]; shellHook = '' echo "Full stack dev environment loaded!" echo "Node: $(node --version)" echo "PostgreSQL: ready (configure in .env)" echo "Redis: ready on localhost:6379" ''; }; } ); }

    Troubleshooting Your Flake

    Package not found?

    nix search nixpkgs python311 # Find the right package name

    Environment variables not working?

    shellHook = '' export DATABASE_URL="postgresql://user:pass@localhost/db" export REDIS_URL="redis://localhost:6379" '';

    Need system packages (C libraries, etc)?

    buildInputs = with pkgs; [ libpq # For PostgreSQL libsodium # For encryption openssl # For SSL/TLS pkg-config # For finding libraries ];

    Next Steps After the Capstone

    Congratulations! You've mastered the fundamentals. Here's where to go:

    What You've Accomplished

    ✓ You can now:
    • Write and understand Nix expressions
    • Create reproducible development environments with flakes
    • Share setups with teammates that work identically everywhere
    • Customize packages and compose complex configurations
    • Troubleshoot and refine Nix setups independently

    Key Takeaways

    Reflection

    Think about the projects you work on. How would your team benefit from:

    Nix makes all of this possible. You now have the skills to build it.

    🎓 Course Complete!

    You've mastered Nix fundamentals and practical applications.

    Next: Share what you've built. Teach others. Join the community.