Skip to content

command-not-found: fix fish db does not exist error - #408910

Closed
joshprk wants to merge 1 commit into
NixOS:masterfrom
joshprk:fish-command-not-found-fix
Closed

joshprk wants to merge 1 commit into
NixOS:masterfrom
joshprk:fish-command-not-found-fix

Conversation

@joshprk

@joshprk joshprk commented May 20, 2025 •

Copy link
Copy Markdown
Contributor

Currently Fish returns a verbose error by directly calling the command-not-found script as it does not catch the possibility that a database does not exist. This commit resolves this by doing what Bash and Zsh does to avoid this.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • Nixpkgs 25.11 Release Notes (or backporting 24.11 and 25.05 Nixpkgs Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
  • NixOS 25.11 Release Notes (or backporting 24.11 and 25.05 NixOS Release notes)
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions Bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels May 20, 2025

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

Hello,

Thanks for the PR.

Can you make sure there's only one commit in this PR ? Please don't close it and don't recreate a new one, you can safely force push in this branch.

Thanks!

@joshprk

joshprk commented May 20, 2025 •

Copy link
Copy Markdown
Contributor Author

Hello,

Thanks for the PR.

Can you make sure there's only one commit in this PR ? Please don't close it and don't recreate a new one, you can safely force push in this branch.

Thanks!

I've made the changes you requested!

@joshprk
joshprk requested a review from drupol May 22, 2025 15:06
@joshprk

joshprk commented Jun 12, 2025

Copy link
Copy Markdown
Contributor Author

Hi, any update on this?

@drupol

drupol commented Jun 12, 2025

Copy link
Copy Markdown
Contributor

Can you ping the maintainer of fish for a second review ?

@joshprk
joshprk requested a review from adamcstephens June 13, 2025 07:05
@jessie-ross

Copy link
Copy Markdown
Contributor

The reason this happens is because fish source itself searches for and uses command-not-found automatically:
https://github.com/fish-shell/fish-shell/blob/d584f36f5d68cc623d3b4fa685d0cb250fe68552/share/functions/fish_command_not_found.fish#L42-L46

While in zsh and bash this needs to be explicitly enabled, and we add prefacing scripting to check for the existence of the database.

Furthermore, the database generally won't exist if a system has been setup using flakes, as this tool relies on nix-channels for the database, so perhaps we should disable this tool by default - new users won't know about this tool if they use flakes and any other shell, which I believe is the general case.

Otherwise, we could move the database check within the perl shell script and simplify this module.

@joshprk

joshprk commented Jun 13, 2025

Copy link
Copy Markdown
Contributor Author

I'm not sure if it relies on nix-channels, from what I tested it relies on nix-index to be enabled. I thought of handling the missing file in command-not-found explicitly but opted against it as it would not be good for a tool to fail silently and we must return 127 if the command is not available.

@jessie-ross

jessie-ross commented Jun 15, 2025 •

Copy link
Copy Markdown
Contributor

I'm not sure if it relies on nix-channels, from what I tested it relies on nix-index to be enabled.

nix-index by default generates a database at xdg::BaseDirectories::with_prefix("nix-index"):
https://github.com/nix-community/nix-index/blob/01a24237f519b5c6d2f9c6a81e0559596f424f80/src/bin/nix-index.rs#L112C16-L112C49

While packages.command-not-found by-default looks for the database at /nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite which is generated by nix-channels:

default = "/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite";

from what I tested it relies on nix-index to be enabled

Perhaps you are using the command-not-found.sh provided by nix-index instead:

substituteInPlace command-not-found.sh \
--subst-var out
install -Dm555 command-not-found.sh -t $out/etc/profile.d

If you enable both packages.command-not-found and packages.nix-index it will trigger a conflict when you try to build the system, and ask you to disable the bash and zsh integrations of one or the other.

@jessie-ross

Copy link
Copy Markdown
Contributor

I thought of handling the missing file in command-not-found explicitly but opted against it as it would not be good for a tool to fail silently and we must return 127 if the command is not available.

Try out #416425, the command-not-found.pl will return 127 itself, and the shell wrapper functions will return the exit code of the last command run (the perl script.)

@joshprk

joshprk commented Jun 15, 2025 •

Copy link
Copy Markdown
Contributor Author

I've seen your PR draft, but I'm a bit confused--is there something I need to change with this PR? I'm not able to see what is relevant as the draft is breaking, while this is just more of a patch that imitates the fixes used for other major shells in the meantime.

@jessie-ross

Copy link
Copy Markdown
Contributor

I've seen your PR draft, but I'm a bit confused--is there something I need to change with this PR? I'm not able to see what is relevant as the draft is breaking, while this is just more of a patch that imitates the fixes used for other major shells in the meantime.

Yeah I ended up trying a deeper solution to the same issue, so #416425 would replace this PR. It disables this command by default, but when it is enabled now instead of printing a database not found message, it prints a more comprehensive message explaining how to fix it.

This is my first contribution to nix btw so I guess I will see how it goes.

@jessie-ross

Copy link
Copy Markdown
Contributor

Hey @joshprk, I managed to get my PR merged which should fix this issue more generally:

@joshprk joshprk closed this Jun 17, 2025
@joshprk
joshprk deleted the fish-command-not-found-fix branch June 17, 2025 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants