Skip to content

feat: migrate from devbox to nix flake#8

Merged
ryoppippi merged 2 commits intomainfrom
migrate-devbox-to-nix-flake
May 27, 2025
Merged

feat: migrate from devbox to nix flake#8
ryoppippi merged 2 commits intomainfrom
migrate-devbox-to-nix-flake

Conversation

@ryoppippi
Copy link
Owner

Summary

This PR migrates the project from Devbox to Nix flakes for development environment management.

Motivation

  • Better reproducibility: Nix flakes provide pinned dependencies and better reproducibility across different systems
  • Native Nix integration: Flakes are the modern way to manage Nix projects, offering better caching and composability
  • Simplified setup: Users familiar with Nix can use standard commands like nix develop, nix build, and nix run
  • Ecosystem compatibility: Better integration with NixOS and other Nix-based tools

Changes

Removed

  • devbox.json - Devbox configuration file
  • devbox.lock - Devbox lock file
  • .devbox/ - Devbox runtime directory

Added

  • flake.nix - Nix flake configuration providing:
    • Development shell with Zig and ZLS
    • Buildable package derivation
    • Runnable application
    • Shell functions matching previous devbox scripts (build, test, fmt, fmt-check, run)

Updated

  • .gitignore - Added Nix-related entries (.direnv/, .envrc, result, result-*)
  • README.md - Updated badges and development section to reflect Nix usage
  • CLAUDE.md - Updated development commands to include Nix alternatives

Migration Guide

For existing developers using devbox:

  1. Remove devbox: rm -rf ~/.local/share/devbox
  2. Install Nix with flakes enabled: https://nixos.org/download
  3. Enter the development shell: nix develop

Or use direnv for automatic environment loading:

echo "use flake" > .envrc
direnv allow

Testing

  • Development shell loads correctly with nix develop
  • All shell functions work (build, test, fmt, etc.)
  • nix build successfully builds the project
  • nix run executes the binary correctly
  • CI should continue to work as it doesn't depend on devbox

Compatibility

This change maintains full compatibility with existing Zig workflows. Developers can still use:

  • zig build directly if they have Zig installed
  • The same build commands within the Nix shell
  • All existing CI/CD pipelines remain unchanged

🤖 Generated with Claude Code

Copy link

@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.

Hello @ryoppippi, 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!

Summary of Changes

Hello! Gemini here, providing a summary of this pull request to help everyone get up to speed quickly.

This PR focuses on migrating the project's development environment management from Devbox to Nix flakes. The primary goal is to leverage Nix's strengths for better reproducibility, native integration, and a more streamlined setup for users familiar with the Nix ecosystem. The changes involve removing the existing Devbox configuration files and runtime directory, introducing a new flake.nix file to define the development shell, buildable package, and runnable application, and updating documentation and .gitignore to reflect the shift.

Highlights

  • Development Environment Migration: The core change is the transition from using Devbox for managing the development environment to using Nix flakes. This aims to improve reproducibility and integrate better with the Nix ecosystem.
  • Nix Flake Implementation: A new flake.nix file is introduced. This file defines the project's development shell (including zig and zls), a buildable package derivation for the zigchat binary, and a runnable application entry point.
  • Removal of Devbox Configuration: The old Devbox configuration (devbox.json, devbox.lock) and its runtime directory (.devbox/) are removed as they are no longer needed.
  • Documentation and Git Ignore Updates: The README.md and CLAUDE.md files are updated to guide users on setting up and using the Nix-based development environment and building/running the project with Nix commands. The .gitignore file is updated to include Nix-specific directories and build outputs.

Changelog

Click here to see the changelog
  • .gitignore
    • Added entries for Nix-related files and directories (.direnv/, .envrc, result, result-*) to prevent them from being tracked.
  • CLAUDE.md
    • Updated the build and run command examples to use nix build and nix run respectively.
    • Removed the alternative devbox run commands for build, run, test, and fmt.
  • README.md
    • Replaced the 'Built with Devbox' badge with a 'Built with Nix' badge.
    • Rewrote the 'Development' section to explain how to set up and use the environment with nix develop or direnv, and how to build with nix build.
  • devbox.json
    • Removed the Devbox configuration file.
  • devbox.lock
    • Removed the Devbox lock file.
  • flake.nix
    • Added a new Nix flake configuration file.
    • Defines inputs for nixpkgs and flake-utils.
    • Provides a default package derivation for zigchat using stdenv.mkDerivation.
    • Defines a default development shell (devShells.default) including zig and zls.
    • Includes a shellHook to print a message and define shell functions (build, test, fmt, fmt-check, run) mirroring the previous Devbox scripts.
    • Defines a default application (apps.default) to run the built zigchat binary.
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 is currently in preview and 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 to provide feedback.

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.


From Devbox to Nix,
A reproducible fix.
Builds now are clean,
A reproducible scene,
No more dependency tricks.

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.

Replace devbox configuration with native Nix flake setup for better
reproducibility and integration with the Nix ecosystem.

Changes:
- Remove devbox.json, devbox.lock, and .devbox/ directory
- Add flake.nix with equivalent Zig and ZLS dependencies
- Add flake.lock for reproducible builds
- Update .gitignore to include Nix-related entries
- Update README.md development section for Nix usage
- Update CLAUDE.md with Nix commands
- Update GitHub Actions CI to use Nix instead of devbox

The flake provides:
- Development shell with Zig and ZLS
- Shell functions matching previous devbox scripts
- Buildable package output for nix build
- Runnable app for nix run

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ryoppippi ryoppippi force-pushed the migrate-devbox-to-nix-flake branch from 1582ba4 to 3e6f873 Compare May 27, 2025 13:20
Copy link

@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 PR successfully migrates the project from Devbox to Nix flakes, which is a positive step towards better reproducibility and native Nix integration. The flake.nix is well-structured, and the documentation updates in README.md and CLAUDE.md are helpful.

I've identified a few areas for potential improvement, primarily concerning tool versioning consistency and documentation completeness. Addressing these will help ensure the Nix environment precisely matches project requirements and is easy for developers to use.

Summary of Findings

  • Zig/ZLS Versioning in Nix Environment: The flake.nix uses Zig/ZLS versions from nixos-unstable, which may differ from the previously pinned 0.14.0 versions. This could impact compatibility if 0.14.0 is a strict requirement.
  • Derivation Source Filtering: The package derivation in flake.nix includes the entire project directory as its source. Filtering this source (e.g., using self or lib.cleanSource) is recommended for better caching and reproducibility.
  • Hardcoded Package Version: The package version is hardcoded in flake.nix, which could lead to synchronization issues with the project's actual version during releases.
  • Documentation for Nix Shell Commands: CLAUDE.md could be enhanced by documenting the usage of test and fmt shell functions available in the Nix development environment.

Merge Readiness

The migration to Nix flakes is a valuable improvement. However, before merging, I strongly recommend clarifying the Zig/ZLS versioning strategy to ensure the development environment aligns with the project's specific version requirements (as highlighted by the high severity comment). The other medium severity suggestions for flake.nix and CLAUDE.md would also enhance the setup and documentation.

As a reviewer, I am not authorized to approve pull requests. Please ensure these points are addressed or discussed, and seek further reviews and approval as per your team's process.

description = "zigchat - CLI tool for OpenAI chat completions";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

Choose a reason for hiding this comment

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

high

The previous devbox.json explicitly pinned zig@0.14.0 and zls@0.14.0. Your CLAUDE.md (line 54) also states, "Zig 0.14.0: The project requires this specific version".

Using pkgs.zig and pkgs.zls from nixpkgs/nixos-unstable (lines 21, 42) will provide the versions available in that channel at the time flake.lock is updated. These might differ from the specific 0.14.0 versions, potentially leading to a development environment that doesn't match the one previously used or documented as required.

Could you clarify if the versions of Zig and ZLS from nixos-unstable have been tested and are confirmed to be compatible, or if steps should be taken to ensure version 0.14.0 is used (e.g., by using a specific nixpkgs revision known to have them, or an overlay)? If 0.14.0 is a strict requirement, this could be a critical point for compatibility.

pname = "zigchat";
version = "0.6.0";

src = ./.;

Choose a reason for hiding this comment

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

medium

The derivation source src = ./.; includes the entire project directory. For better reproducibility, caching, and to avoid including unnecessary files (like .git/, flake.lock, etc.) in the build sandbox, it's often recommended to filter the source.

Have you considered using src = self; (if this flake file is at the root of your git repository and all sources are tracked) or src = pkgs.lib.cleanSource ./.;? self would typically refer to the git-tracked files of the flake's repository root.

          src = self; # Or pkgs.lib.cleanSource ./.;


zigchat = pkgs.stdenv.mkDerivation {
pname = "zigchat";
version = "0.6.0";

Choose a reason for hiding this comment

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

medium

The package version 0.6.0 is hardcoded here. While it currently aligns with the version in build.zig, this creates another place that needs manual updating for new releases.

To improve maintainability, have you considered if there's a way to derive this version from a single source of truth (e.g., build.zig) during flake evaluation? If that's too complex, ensuring this is part of the release checklist would be important. This is more of a long-term maintainability suggestion.

```bash
zig build test # Run all tests
devbox run test # Alternative using devbox
```

Choose a reason for hiding this comment

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

medium

The "Test" section details how to run tests using zig build test. Since the flake.nix now provides convenient shell functions like test (and fmt, fmt-check), it would be helpful to document their usage here as well, similar to how nix build and nix run are shown as alternatives.

Consider adding a note for running tests and formatting via the Nix dev shell. For example:

 ### Test
 ```bash
 zig build test              # Run all tests
+# Alternatively, within the Nix development shell (`nix develop`):
+# test

Format

zig fmt .                   # Format code
zig build fmt-check        # Check formatting without modifying
+# Alternatively, within the Nix development shell (`nix develop`):
+# fmt                       # Format code
+# fmt-check                 # Check formatting

Switch to using mitchellh/zig-overlay to pin Zig to exactly version 0.14.0,
ensuring consistent builds across all environments.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ryoppippi ryoppippi merged commit 63628af into main May 27, 2025
20 checks passed
@ryoppippi ryoppippi deleted the migrate-devbox-to-nix-flake branch May 27, 2025 13:27
@ryoppippi ryoppippi requested a review from Copilot May 27, 2025 13:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates the development environment management from Devbox to Nix flakes to improve reproducibility and native Nix integration.

  • Removed all Devbox configuration files and directories
  • Added a new flake.nix with configurations for development shell, build, and app packaging
  • Updated documentation and CI workflows to reflect Nix usage

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
flake.nix New flake configuration defining build, dev shell, and app setup using Nix flakes
devbox.json Removed Devbox configuration
README.md Updated badges and instructions for Nix-based development
CLAUDE.md Updated commands to use Nix instead of Devbox
.github/workflows/ci.yaml Revised CI steps to install Nix and run build/test commands using Nix

let
pkgs = nixpkgs.legacyPackages.${system};
zigPkgs = zig-overlay.packages.${system};
zig = zigPkgs."0.14.0";
Copy link

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

Consider pinning the zig-overlay input to a specific commit or revision, if not already done, to ensure reproducibility in the flake setup.

Copilot uses AI. Check for mistakes.
- name: Build
run: |
devbox run build --verbose -Dtarget=${{ matrix.targets }} -Doptimize=${{ matrix.optimize }}
nix develop -c zig build --verbose -Dtarget=${{ matrix.targets }} -Doptimize=${{ matrix.optimize }}
Copy link

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

Ensure that the matrix variables are correctly resolved and passed to the build command; consider quoting them if there's a risk of unexpected spacing or formatting issues.

Copilot uses AI. Check for mistakes.
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.

2 participants