nixos-config icon indicating copy to clipboard operation
nixos-config copied to clipboard

nix-index-fork

Open srid opened this issue 1 year ago • 13 comments

Trying https://github.com/gvolpe/nix-index/pull/1

srid avatar Dec 20 '24 15:12 srid

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.

gvolpe avatar Dec 20 '24 16:12 gvolpe

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:

https://github.com/srid/nixos-config/blob/68834596c1a68b9f68d6722f4e4f17033a715578/modules/home/default.nix#L9

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

srid avatar Dec 20 '24 16:12 srid

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 😄

gvolpe avatar Dec 20 '24 17:12 gvolpe

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

srid avatar Dec 20 '24 18:12 srid

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 avatar Dec 20 '24 19:12 gvolpe

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;?

gvolpe avatar Dec 20 '24 19:12 gvolpe

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)

srid avatar Dec 20 '24 20:12 srid

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 https://github.com/NixOS/nixpkgs/issues/39789#issuecomment-1000276113 and https://github.com/nix-community/nix-index-database/issues/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.

gvolpe avatar Dec 21 '24 09:12 gvolpe

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.

srid avatar Dec 21 '24 13:12 srid

@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: https://github.com/gvolpe/nix-config/commit/da65d6b68c9c88353af1de6df10cfb9341330b5f

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.

gvolpe avatar Dec 22 '24 17:12 gvolpe

Trying with d4fe1a9be97528da6ee591e950d51a5bdbd77fd5 (per https://github.com/gvolpe/nix-index/pull/1#issuecomment-2558611564) =>

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

srid avatar Dec 22 '24 21:12 srid

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 avatar Dec 23 '24 07:12 gvolpe

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;
   };
 }

gvolpe avatar Dec 23 '24 08:12 gvolpe