Skip to content

feat(fish): add global dev command for nix devshell - #540

Merged
shunkakinoki merged 1 commit into
mainfrom
feat/dev-command
Jan 11, 2026
Merged

feat(fish): add global dev command for nix devshell#540
shunkakinoki merged 1 commit into
mainfrom
feat/dev-command

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Jan 11, 2026

Copy link
Copy Markdown
Owner

Changes

  • Add dev fish abbreviation for entering Nix devshells from anywhere
  • Creates _dev_function.fish that searches for nearest flake.nix in parent directories
  • Falls back to ~/dotfiles devshell if no local flake found

Technical Details

  • Function walks up directory tree looking for flake.nix
  • Sets DEVENV_ROOT properly for devenv integration
  • Passes through any additional arguments to nix develop

Testing

  • make switch completes successfully
  • dev from dotfiles directory enters devshell
  • dev from random directory falls back to dotfiles devshell

Generated with Claude Code by claude-opus-4-5-20251101


Summary by cubic

Add a global dev command in fish to enter a Nix devshell from any directory. It finds the closest flake.nix or falls back to ~/dotfiles.

  • New Features
    • Added a dev abbreviation mapped to _dev_function.
    • Searches parent directories for flake.nix; otherwise uses ~/dotfiles.
    • Sets DEVENV_ROOT and forwards args to nix develop.

Written for commit 880efe7. Summary will update on new commits.

Add a `dev` fish abbreviation that enters a Nix development shell from
anywhere. The function searches for the nearest flake.nix in parent
directories and uses that devshell, or falls back to ~/dotfiles if no
flake is found.
Copilot AI review requested due to automatic review settings January 11, 2026 15:15
@coderabbitai

coderabbitai Bot commented Jan 11, 2026

Copy link
Copy Markdown
📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • New Features
    • Added a new shell abbreviation for quickly entering development environments. The feature automatically searches for project configuration in parent directories and falls back to a default location if none is found.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

This PR introduces a new Fish shell function _dev_function that automatically locates the nearest flake.nix file by traversing parent directories, with a fallback to $HOME/dotfiles, then enters the corresponding Nix development environment. A dev abbreviation is registered to invoke this function.

Changes

Cohort / File(s) Summary
Fish Function Definition
home-manager/programs/fish/functions/_dev_function.fish
New function implementation: searches upward for flake.nix, falls back to $HOME/dotfiles, outputs target directory, and invokes nix develop with the identified directory.
Fish Configuration
home-manager/programs/fish/default.nix
Registered _dev_function in the function generation list and added dev abbreviation mapping to invoke the new function.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

Hop through the directories, up we go,
In search of flake.nix's gentle glow,
A dev shortcut, swift and true,
Nix environments await for you! 🐰✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a global dev command for Nix devshell in the fish shell configuration.
Description check ✅ Passed The description clearly relates to the changeset, providing context about the dev abbreviation, function behavior, and testing performed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/dev-command

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @shunkakinoki, 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 enhances the Fish shell experience by introducing a convenient dev command. This command intelligently locates and activates the appropriate Nix development shell based on the presence of a flake.nix file in the current or parent directories, providing a seamless way to manage development environments. It also includes a fallback mechanism to a default dotfiles devshell, ensuring a consistent development setup.

Highlights

  • New dev abbreviation for Fish shell: Introduces a new dev abbreviation in the Fish shell configuration, allowing users to quickly enter Nix development shells from any directory.
  • Intelligent flake.nix discovery: A new _dev_function.fish script is added that automatically searches for the nearest flake.nix file in parent directories to determine the correct Nix devshell to enter.
  • Fallback to dotfiles devshell: If no flake.nix is found in the current directory or its parents, the function gracefully falls back to entering the devshell defined in ~/dotfiles.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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.

@mesa-dot-dev

mesa-dot-dev Bot commented Jan 11, 2026

Copy link
Copy Markdown

Mesa Description

TL;DR

Added a global dev command for entering Nix devshells in the fish shell.

What changed?

  • Added dev fish abbreviation for entering Nix devshells from anywhere
  • Created _dev_function.fish that searches for nearest flake.nix in parent directories
  • Implemented fallback to ~/dotfiles devshell if no local flake is found
  • Function walks up the directory tree looking for flake.nix
  • Sets DEVENV_ROOT properly for devenv integration
  • Passes through any additional arguments to nix develop

Description generated by Mesa. Update settings

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

Copy link
Copy Markdown
Contributor

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 convenient dev command for entering Nix development shells. The implementation correctly searches for a flake.nix file in parent directories and falls back to a default. My review includes one high-severity finding related to a logic bug in the directory traversal, which could cause it to miss a flake.nix file in the root directory. I've provided a code suggestion to fix this.

Comment on lines +6 to +13
set -l check_dir (pwd)
while test "$check_dir" != "/"
if test -f "$check_dir/flake.nix"
set target_dir $check_dir
break
end
set check_dir (dirname $check_dir)
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The current loop for finding flake.nix will not check the root directory /. The loop condition test "$check_dir" != "/" causes the loop to terminate when check_dir becomes /, without checking for flake.nix in that directory. This means if a flake.nix exists only at the filesystem root, it won't be found, and the function will incorrectly fall back to the default. The suggested change fixes this by adjusting the loop to correctly handle traversal up to and including the root directory.

    set -l check_dir (pwd)
    while true
        if test -f "$check_dir/flake.nix"
            set target_dir $check_dir
            break
        end
        if test "$check_dir" = "/"; break; end
        set check_dir (dirname $check_dir)
    end

@shunkakinoki
shunkakinoki merged commit 855eb91 into main Jan 11, 2026
29 of 31 checks passed
@shunkakinoki
shunkakinoki deleted the feat/dev-command branch January 11, 2026 15:18

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
home-manager/programs/fish/functions/_dev_function.fish (1)

6-13: Consider checking the root directory.

The loop exits when check_dir reaches "/" without checking for flake.nix at the root itself. While having a flake.nix at / is extremely unlikely in practice, you could make the traversal complete by adjusting the loop condition.

♻️ Optional fix to include root directory check
-    set -l check_dir (pwd)
-    while test "$check_dir" != "/"
+    set -l check_dir (pwd)
+    while true
         if test -f "$check_dir/flake.nix"
             set target_dir $check_dir
             break
         end
+        test "$check_dir" = "/" && break
         set check_dir (dirname $check_dir)
     end
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between aec622a and 880efe7.

📒 Files selected for processing (2)
  • home-manager/programs/fish/default.nix
  • home-manager/programs/fish/functions/_dev_function.fish
🧰 Additional context used
📓 Path-based instructions (6)
**/*.nix

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.nix: Use nixfmt for formatting all Nix files
Document complex configurations with comments in Nix files

**/*.nix: Use 2 spaces for indentation in Nix files
Keep line length under 100 characters in Nix files
Sort attribute sets alphabetically in Nix files
Use consistent spacing around operators in Nix files
Format lists and sets consistently in Nix files

Use treefmt.toml for formatting Nix files

**/*.nix: Use mkOption for configurable options in Nix modules
Implement proper typing for all options in Nix modules
Follow the Nix expression language style guide

Files:

  • home-manager/programs/fish/default.nix
**/default.nix

📄 CodeRabbit inference engine (CLAUDE.md)

Use default.nix files for module exports

Files:

  • home-manager/programs/fish/default.nix
home-manager/programs/*/default.nix

📄 CodeRabbit inference engine (.cursor/rules/home-manager.mdc)

Program configurations should be located in home-manager/programs/<name>/ and use home-manager's built-in modules when available

Files:

  • home-manager/programs/fish/default.nix
home-manager/programs/**/default.nix

📄 CodeRabbit inference engine (.cursor/rules/home-manager.mdc)

Program configurations must include all necessary dependencies in their configuration

Files:

  • home-manager/programs/fish/default.nix
home-manager/**/*.nix

📄 CodeRabbit inference engine (.cursor/rules/home-manager.mdc)

home-manager/**/*.nix: Use typed options whenever possible in Nix configurations
Document all configuration options in Nix modules and programs
Follow home-manager's module structure and keep configurations modular
Use proper indentation and formatting in Nix configuration files

Files:

  • home-manager/programs/fish/default.nix
home-manager/programs/**/*.nix

📄 CodeRabbit inference engine (.cursor/rules/home-manager.mdc)

Follow program-specific best practices in program configuration files

Program configurations in home-manager/programs/ should be organized by program name, include all necessary dependencies, use home.packages for package installations, and use programs.<name> when available in home-manager

Files:

  • home-manager/programs/fish/default.nix
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: Agent
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Mesa Review
  • GitHub Check: e2e-run (NixOS, ubuntu-latest)
  • GitHub Check: e2e-run (Ubuntu, ubuntu-latest)
  • GitHub Check: shell-lint
  • GitHub Check: shell-test
  • GitHub Check: nix-nixos
  • GitHub Check: lua-neovim
  • GitHub Check: lua-neovim-test
  • GitHub Check: nix-linux
  • GitHub Check: docker-build-push (linux/amd64, amd64, ubuntu-latest)
  • GitHub Check: docker-build-push (linux/arm64, arm64, ubuntu-24.04-arm)
🔇 Additional comments (4)
home-manager/programs/fish/default.nix (1)

68-68: LGTM! Clean integration of the new dev function.

The _dev_function is properly registered as a shell abbreviation and correctly included in the function source list, following the established pattern for other function-based abbreviations.

Also applies to: 141-141

home-manager/programs/fish/functions/_dev_function.fish (3)

1-3: LGTM! Proper function definition.

The function follows Fish best practices with a descriptive flag and proper local variable initialization.


15-18: Verify fallback behavior when $HOME/dotfiles doesn't exist.

The function assumes $HOME/dotfiles exists and contains a valid flake.nix. If the directory doesn't exist or lacks a flake, nix develop will fail with an error message. Consider whether you want to add validation before invoking nix develop, or if relying on nix's error messages is acceptable.

♻️ Optional: Add validation for fallback directory
     # Fallback to dotfiles if no flake found
     if test -z "$target_dir"
         set target_dir "$HOME/dotfiles"
+        if not test -d "$target_dir"
+            echo "Error: Fallback directory $target_dir does not exist" >&2
+            return 1
+        end
     end

20-22: LGTM! Correct devshell invocation.

The command properly:

  • Sets DEVENV_ROOT for devenv integration
  • Passes the target directory to nix develop
  • Forwards additional arguments via $argv

The informational message provides good UX feedback to the user.

@mesa-dot-dev mesa-dot-dev Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Performed full review of aec622a...880efe7

Analysis

  1. Environment variable propagation issue - The DEVENV_ROOT setting may not correctly propagate to spawned shell sessions, which could cause unexpected behavior.

  2. Hardcoded fallback path (~/dotfiles) reduces portability and flexibility of the solution for different environments or users.

  3. Missing validation for valid devShell definitions in found flakes, which could lead to runtime errors when attempting to use invalid configurations.

  4. Performance concerns with the directory traversal implementation - always walking up to the root directory could be inefficient on deeply nested paths or network filesystems.

Tip

Help

Slash Commands:

  • /review - Request a full code review
  • /review latest - Review only changes since the last review
  • /describe - Generate PR description. This will update the PR body or issue comment depending on your configuration
  • /help - Get help with Mesa commands and configuration options

0 files reviewed | 1 comments | Edit Agent SettingsRead Docs

# Check if current directory or any parent has flake.nix
set -l check_dir (pwd)
while test "$check_dir" != "/"
if test -f "$check_dir/flake.nix"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Medium

The function doesn't verify if the found flake.nix actually contains a valid devShell definition. Consider adding a check or handling the error case when nix develop fails on an incompatible flake. A simple approach could be catching the error and displaying a helpful message.

Agent: 🏛 Architecture • Fix in Cursor • Fix in Claude

Prompt for Agent
Task: Address review feedback left on GitHub.
Repository: shunkakinoki/dotfiles#540
File: home-manager/programs/fish/functions/_dev_function.fish#L8
Action: Open this file location in your editor, inspect the highlighted code, and resolve the issue described below.

Feedback:
The function doesn't verify if the found `flake.nix` actually contains a valid devShell definition. Consider adding a check or handling the error case when `nix develop` fails on an incompatible flake. A simple approach could be catching the error and displaying a helpful message.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2 issues found across 2 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="home-manager/programs/fish/functions/_dev_function.fish">

<violation number="1" location="home-manager/programs/fish/functions/_dev_function.fish:7">
P2: The loop condition exits when `check_dir` becomes `/` without checking if `flake.nix` exists at the root directory. If a `flake.nix` exists only at `/`, it won't be found and the function will incorrectly fall back to `~/dotfiles`. Consider restructuring the loop to check the root directory before exiting.</violation>

<violation number="2" location="home-manager/programs/fish/functions/_dev_function.fish:22">
P1: Fish does not support `VAR=value command` syntax, so this line tries to run a command named `DEVENV_ROOT=…` and never sets the variable before invoking `nix develop`. Use `env` or `set -lx` to export DEVENV_ROOT for the command.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.


# Enter the devshell
echo "Entering devshell in $target_dir"
DEVENV_ROOT=$target_dir nix develop $target_dir $argv

@cubic-dev-ai cubic-dev-ai Bot Jan 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: Fish does not support VAR=value command syntax, so this line tries to run a command named DEVENV_ROOT=… and never sets the variable before invoking nix develop. Use env or set -lx to export DEVENV_ROOT for the command.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At home-manager/programs/fish/functions/_dev_function.fish, line 22:

<comment>Fish does not support `VAR=value command` syntax, so this line tries to run a command named `DEVENV_ROOT=…` and never sets the variable before invoking `nix develop`. Use `env` or `set -lx` to export DEVENV_ROOT for the command.</comment>

<file context>
@@ -0,0 +1,23 @@
+
+    # Enter the devshell
+    echo "Entering devshell in $target_dir"
+    DEVENV_ROOT=$target_dir nix develop $target_dir $argv
+end
</file context>
Suggested change
DEVENV_ROOT=$target_dir nix develop $target_dir $argv
env DEVENV_ROOT=$target_dir nix develop $target_dir $argv
Fix with Cubic


# Check if current directory or any parent has flake.nix
set -l check_dir (pwd)
while test "$check_dir" != "/"

@cubic-dev-ai cubic-dev-ai Bot Jan 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: The loop condition exits when check_dir becomes / without checking if flake.nix exists at the root directory. If a flake.nix exists only at /, it won't be found and the function will incorrectly fall back to ~/dotfiles. Consider restructuring the loop to check the root directory before exiting.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At home-manager/programs/fish/functions/_dev_function.fish, line 7:

<comment>The loop condition exits when `check_dir` becomes `/` without checking if `flake.nix` exists at the root directory. If a `flake.nix` exists only at `/`, it won't be found and the function will incorrectly fall back to `~/dotfiles`. Consider restructuring the loop to check the root directory before exiting.</comment>

<file context>
@@ -0,0 +1,23 @@
+
+    # Check if current directory or any parent has flake.nix
+    set -l check_dir (pwd)
+    while test "$check_dir" != "/"
+        if test -f "$check_dir/flake.nix"
+            set target_dir $check_dir
</file context>
Fix with Cubic

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adds a convenient dev abbreviation for entering Nix development shells from any directory. The function searches upward through parent directories for a flake.nix file and falls back to the dotfiles directory if none is found.

Changes:

  • Added _dev_function.fish that implements directory tree traversal to find nearest flake.nix
  • Registered dev abbreviation in Fish configuration
  • Integrated function into the Fish functions list

Reviewed changes

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

File Description
home-manager/programs/fish/functions/_dev_function.fish New function implementing upward directory search and devshell entry logic
home-manager/programs/fish/default.nix Registered dev abbreviation and added function to config file mapping

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


# Enter the devshell
echo "Entering devshell in $target_dir"
DEVENV_ROOT=$target_dir nix develop $target_dir $argv

Copilot AI Jan 11, 2026

Copy link

Choose a reason for hiding this comment

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

The POSIX-style environment variable syntax works in Fish but is not idiomatic. Consider using the Fish-native approach with begin; set -lx DEVENV_ROOT $target_dir; nix develop $target_dir $argv; end or using env DEVENV_ROOT=$target_dir nix develop $target_dir $argv for better clarity and consistency with Fish conventions.

Suggested change
DEVENV_ROOT=$target_dir nix develop $target_dir $argv
env DEVENV_ROOT=$target_dir nix develop $target_dir $argv

Copilot uses AI. Check for mistakes.

# Fallback to dotfiles if no flake found
if test -z "$target_dir"
set target_dir "$HOME/dotfiles"

Copilot AI Jan 11, 2026

Copy link

Choose a reason for hiding this comment

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

The fallback to "$HOME/dotfiles" doesn't check if the directory or flake.nix exists there. If the dotfiles directory doesn't exist or doesn't contain a flake.nix, the nix develop command will fail without a clear error message. Consider adding validation to check if the fallback directory and flake.nix exist before attempting to enter the devshell.

Suggested change
set target_dir "$HOME/dotfiles"
set -l fallback_dir "$HOME/dotfiles"
if test -d "$fallback_dir" -a -f "$fallback_dir/flake.nix"
set target_dir "$fallback_dir"
else
echo "Error: No flake.nix found in current directory tree, and fallback '$fallback_dir' is missing or lacks flake.nix." >&2
return 1
end

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