Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions home-manager/programs/fish/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
coxeh = "_coxeh_function";
coxel = "_coxel_function";
coxelh = "_coxelh_function";
dev = "_dev_function";
ocxe = "_ocxe_function";
ocxeh = "_ocxeh_function";
gco = "_gco_function";
Expand Down Expand Up @@ -137,6 +138,7 @@
"_coxeh_function"
"_coxel_function"
"_coxelh_function"
"_dev_function"
"_ocxe_function"
"_ocxeh_function"
"_fish_shortcuts"
Expand Down
23 changes: 23 additions & 0 deletions home-manager/programs/fish/functions/_dev_function.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function _dev_function --description "Enter Nix development shell"
# Find the nearest directory with flake.nix, or use dotfiles
set -l target_dir ""

# 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

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.

set target_dir $check_dir
break
end
set check_dir (dirname $check_dir)
end
Comment on lines +6 to +13

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


# 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.
end

# 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

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.
end
Loading