Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix-index-fork #72

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

nix-index-fork #72

wants to merge 4 commits into from

Conversation

srid
Copy link
Owner

@srid srid commented Dec 20, 2024

@gvolpe
Copy link

gvolpe commented Dec 20, 2024

I tried to build it locally and got this error:

 error: The option `home-manager.users.srid.programs.nix-index-fork' does not exist. Definition values:
       - In `/nix/store/ry1gysi3kqddhzp7ml9arzbmb24rshyv-source/modules/home/all/terminal.nix':

The programs.nix-index-fork option should be top level. If you place it under modules/home/all/nix-index.nix with the following content, it builds:

{
  programs = {
    nix-index-fork = {
      enable = true;
      enableZshIntegration = true;
      enableNixCommand = true;
    };
  };
}

Not in your terminal.nix file because that expects a few different arguments and it's being imported incorrectly AFAIU.

@srid
Copy link
Owner Author

srid commented Dec 20, 2024

Not in your terminal.nix file because that expects a few different arguments and it's being imported incorrectly AFAIU

It is just standard home-manager import:

./all/terminal.nix

What do you mean by imported incorrectly? The flake argument is passed thorugh specialArgs, via https://nixos-unified.org/specialArgs.html

@gvolpe
Copy link

gvolpe commented Dec 20, 2024

I got it building by disabling nix-index-database too, not sure if that conflicts with nix-index-fork or not.

What do you mean by imported incorrectly?

I mean that it ends up looking for it at home-manager.users.srid.programs.nix-index-fork instead of programs.nix-index-fork. If I try doing something wrong in my nix config, I get this error instead:

 error: The option `programs.nix-index-fork2' does not exist. Definition values:
       - In `/nix/store/5xavc8cqcwcm6z9ky45cif7x0vwkyxnr-source/home/shared':

See the difference? Not sure how you're wiring things, but hopefully that's a hint 😄

@srid
Copy link
Owner Author

srid commented Dec 20, 2024

I mean that it ends up looking for it at home-manager.users.srid.programs.nix-index-fork instead of programs.nix-index-fork

The former is the correct module key, if using from nix-darwin or NixOS config. The latter, I suppose, applies to standalone home-manager config which my repo does not use.

I am able to get it to build by removing nix-index-database entirely:

image

However, without nix-index-database this thing becomes less useful (as you need a manual intervention):

image

Not sure what is going on, but from a quick look, nix-index-database is hardcoded to enable programs.nix-index and that probably conflicts with the (simultaneous) use of your fork:

https://github.com/nix-community/nix-index-database/blob/311d6cf3ad3f56cb051ffab1f480b2909b3f754d/nix/shared.nix#L6

@gvolpe
Copy link

gvolpe commented Dec 20, 2024

Yeah that makes sense, I can look into nix-index-database and see if I can get them to play along together. I'm generating the index manually every time I upgrade my system, which happens once a month, so not a big deal as I have scripts for it.

@gvolpe
Copy link

gvolpe commented Dec 20, 2024

Not sure what is going on, but from a quick look, nix-index-database is hardcoded to enable programs.nix-index and that probably conflicts with the (simultaneous) use of your fork:

Curious. Does it work if you also add programs.nix-index.enable = false;?

@srid
Copy link
Owner Author

srid commented Dec 20, 2024

Does it work if you also add programs.nix-index.enable = false;?

It builds, but doesn't work (index still needs to be manually generated)

@gvolpe
Copy link

gvolpe commented Dec 21, 2024

Got it 👍🏽 I looked into nix-index-database and besides needing a lot overrides to make it compatible, I realized it's not for me because it generates a full index and nix-index is way too slow to use such a big index (at least for me and a few other users, see NixOS/nixpkgs#39789 (comment) and nix-community/nix-index-database#130).

I may come back to it if generating a smaller DB becomes an option, but for now I'll stick with a locally generated DB via nix-index --filter-prefix '/bin/', this works great for me as I only update NixOS once a month.

@srid
Copy link
Owner Author

srid commented Dec 21, 2024

That's interesting, I didn't know that. I'd very much prefer a smaller index as well, but having that automated would be great. Kind of surprised that no one has bothered to do this in nix-index-database?

I wonder if there's demand for an efficient & flake-friendly fork.

@gvolpe
Copy link

gvolpe commented Dec 22, 2024

@srid I think I got something working, if you'd like to test it, just don't use the Home Manager module from nix-index-database. Here's what it takes to use my fork: gvolpe/nix-config@da65d6b

You can see the first database release on my fork here: https://github.com/gvolpe/nix-index-database/releases/tag/2024-12-22-163440

The small database is about ~17 times smaller than the full database.

There's some room for improvement, but if there's enough interest, I'll work on upstreaming these changes.

@srid
Copy link
Owner Author

srid commented Dec 22, 2024

Trying with d4fe1a9 (per gvolpe/nix-index#1 (comment)) =>

       error: attribute 'version' missing

       at /nix/store/2m2vrj4cr0d9lgs92z6g4cfcmd49fxhg-source/wrapper.nix:8:31:

            7| symlinkJoin {
            8|   name = "nix-index-with-db-${nix-index.version}";
             |                               ^
            9|   paths = [ nix-index ];

Not sure what I'm missing ...

@gvolpe
Copy link

gvolpe commented Dec 23, 2024

Hmm curious if the overlay that comes with the nix-index HM module doesn't work for your multi-arch setup. Try this?

nix-index-fork.package = flake.inputs.nix-index.packages.${pkgs.system}.default;

@gvolpe
Copy link

gvolpe commented Dec 23, 2024

Yeah this builds for me (also removing the nix-index-database HM module, not needed):

diff --git a/modules/home/all/nix-index.nix b/modules/home/all/nix-index.nix
index ddf7bae..abebb49 100644
--- a/modules/home/all/nix-index.nix
+++ b/modules/home/all/nix-index.nix
@@ -5,19 +5,15 @@ let
   inherit (flake) inputs;
 in
 {
-  imports = [
-    inputs.nix-index-database.hmModules.nix-index
-  ];
-
   programs = {
     # Command not found handler based on nixpkgs
     nix-index-fork = {
       enable = true;
       enableZshIntegration = true;
       enableNixCommand = true;
+      package = inputs.nix-index.packages.${pkgs.system}.default;
       database = inputs.nix-index-database.packages.${pkgs.system}.nix-index-small-database;
     };
     command-not-found.enable = false;
-    # nix-index-database.comma.enable = true;
   };
 }

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