Skip to content

Conversation

svnlto
Copy link
Contributor

@svnlto svnlto commented Aug 20, 2025

Summary

This PR adds a simple and idiomatic Nix flake for reproducible development environment setup, following the approach suggested in #219. This is a much simpler alternative to the closed PR #219 that had 280+ lines of complex configuration.

Key Features

  • Simple Nix Flake (flake.nix): 63 lines vs 280+ in the previous attempt
  • Standard Nix Patterns: Uses buildPythonApplication and mkShell
  • Hybrid Development Environment: Nix provides system dependencies + Python venv for packages
  • direnv Integration (.envrc): Automatic environment activation
  • Zero Breaking Changes: No Python version bump, no lockfiles, maintains existing workflows
  • Cross-Platform: Works on Linux, macOS, and NixOS
  • Enhanced Pre-commit Setup: Added standard formatting and validation hooks

Benefits Over Previous Approach

  • 90% less code (63 lines vs 280+ lines)
  • No uv2nix or pyproject-nix complexity
  • No Python version bump needed (keeps 3.9+ support)
  • No lockfile generation required
  • Standard Nix development patterns
  • Less maintenance overhead
  • Works alongside existing ./run-server.sh setup

Files Added/Modified

  • flake.nix - Simple Nix flake configuration with improved dependency management
  • flake.lock - Nix lock file for reproducibility
  • .envrc - direnv configuration for auto-activation
  • .gitignore - Exclude Nix development artifacts
  • code_quality_checks.sh - Exclude .nix-venv from checks
  • run_integration_tests.sh - Robust Nix environment detection
  • docs/contributions.md - Document Nix development setup
  • .pre-commit-config.yaml - Added comprehensive standard hooks for code quality

Pre-commit Improvements

Added standard pre-commit hooks for better code quality and consistency:

  • File formatting: trailing-whitespace, end-of-file-fixer, mixed-line-ending
  • Syntax validation: check-yaml, check-json, check-toml
  • Safety checks: check-merge-conflict, check-added-large-files
  • Updated excludes: Added Nix directories (.nix-venv/, .direnv/)

Code Review Feedback Addressed

  • ✅ Added pytest-mock to devShell packages for complete test environment
  • ✅ Switched to pip install -e . for better dependency management from pyproject.toml
  • ✅ Added python-semantic-release to development dependencies
  • ✅ Fixed IN_NIX_SHELL detection to handle pure/impure values properly
  • ✅ Added trailing newlines to all configuration files

Usage

# Option 1: Manual activation
nix develop

# Option 2: Automatic with direnv
direnv allow

# Build package
nix build

# Run directly
nix run

This addresses the need for reproducible development environments while keeping the implementation simple and maintainable.

Test plan

  • Nix flake builds successfully (nix build)
  • Development shell provides all dependencies (nix develop)
  • Hybrid environment works with existing scripts
  • Code quality checks pass with exclusions
  • Integration tests detect Nix environment properly
  • Pre-commit hooks work correctly and format codebase
  • All PR feedback addressed and verified
  • Documentation is accurate and helpful
  • Existing non-Nix workflows remain unaffected

Fixes the need for Nix support mentioned in #219 with a much simpler approach, plus enhanced code quality tooling.

svnlto added 7 commits August 15, 2025 10:37
This provides a clean, maintainable alternative to the complex uv2nix approach
in PR BeehiveInnovations#219. Benefits:

- 90% less code (30 lines vs 280+ lines)
- Uses standard buildPythonApplication from nixpkgs
- No Python version bump needed (keeps 3.9+ support)
- No uv.lock file required
- Includes direnv support for automatic dev environment
- Follows standard Nix patterns for easier maintenance

The flake provides:
- `nix build` - Build the package
- `nix run` - Run zen-mcp-server directly
- `nix develop` - Development shell with all dependencies
- `nix profile install` - Install from GitHub

Also includes .envrc for direnv users to automatically activate
the development environment when entering the directory.
- Add Nix flake as development environment option alongside traditional setup
- Document advantages: reproducible environment, zero setup, isolated dependencies
- Include all available Nix commands (develop, build, run, install)
- Explain direnv integration for automatic environment activation
- Provide clear guidance for Nix users contributing to the project
This enables direnv to automatically load .env file contents into the
environment, making nix run work correctly with API keys and other
configuration from .env files.

Before: nix run failed with missing API keys despite .env file
After: nix run works correctly with environment loaded from .env

Completes the Nix flake integration by ensuring configuration
works seamlessly in both development and packaged environments.
- Simplified Python dependencies to avoid pydantic-core conflicts
- Added LD_LIBRARY_PATH for proper shared library loading
- Added pytest-asyncio for complete test compatibility
- Modified run_integration_tests.sh to detect and work with Nix environment
- Fixed integration tests to run successfully in both traditional and Nix environments

All functionality now works properly:
- nix develop: Full development environment with all tools
- nix build/run: Working package build and execution
- ./code_quality_checks.sh: All 799 unit tests pass
- ./run_integration_tests.sh: Integration tests work in both environments
Uses Nix for system tools + pip venv for Python packages.
Resolves pydantic binary issues while keeping Nix benefits.
All tests now work in Nix environment.
Added .nix-venv exclusions to ruff, black, and isort commands
to prevent formatting virtual environment files created by
the Nix development shell.
- Added flake.lock for reproducible Nix builds
- Added .nix-venv/, .direnv/, and result to .gitignore
- Ensures clean git status with Nix development environment
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @svnlto, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a simple Nix flake to provide a reproducible development environment for the Zen MCP Server. It offers a streamlined alternative to previous complex attempts by integrating Nix for system dependencies while maintaining a Python virtual environment for package management. The changes ensure cross-platform compatibility and zero breaking changes to existing workflows, making the development setup more robust and easier to manage.

Highlights

  • Reproducible Development Environment: Implemented a simple Nix flake (flake.nix) for reproducible development, significantly reducing configuration complexity compared to prior attempts.
  • Hybrid Environment Setup: Established a hybrid development environment where Nix manages system dependencies and a Python virtual environment handles Python package management.
  • Automated Environment Activation: Integrated direnv via a new .envrc file to automatically activate the Nix development shell upon directory entry.
  • Tooling Integration: Updated code_quality_checks.sh and run_integration_tests.sh to properly handle the new Nix environment, excluding Nix-managed directories from checks and detecting Nix shell activation.
  • Documentation: Added comprehensive documentation in docs/contributions.md detailing the Nix setup, its benefits, and usage instructions for developers.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a simple and idiomatic Nix flake to provide a reproducible development environment, which is a great improvement for contributor onboarding and consistency. The implementation is clean and follows standard Nix patterns. My review focuses on improving the maintainability of the dependency management within the flake and ensuring the development environment is complete and robust. I've suggested changes to avoid hardcoding dependencies in the shellHook and to include all necessary development packages.

svnlto and others added 3 commits August 20, 2025 12:25
- Add pytest-mock to devShell packages for complete test environment
- Use pip install -e . for better dependency management from pyproject.toml
- Add python-semantic-release to dev dependencies
- Fix IN_NIX_SHELL detection to handle pure/impure values properly
- Add standard pre-commit hooks for comprehensive formatting and validation
- Update exclude patterns to include Nix development directories

Standard hooks added:
- trailing-whitespace, end-of-file-fixer for file consistency
- check-yaml, check-json, check-toml for syntax validation
- check-merge-conflict, check-added-large-files for safety
- mixed-line-ending for consistent LF line endings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant