nix-community / nix-index-database

Weekly updated nix-index database [maintainer=@Mic92]
MIT License
281 stars 25 forks source link

Explain setup with home-manager but without flakes #73

Closed shoo8eem1A closed 11 months ago

shoo8eem1A commented 1 year ago

The current README explains how to setup nix-index-database with home-manager and flake. But flake is still experimental and some of us (me included) have not enabled it yet.

I think I managed to setup nix-index-database with home-manager and no flake with the following code. Is it something we should add to the README? Is there any problem with this code?

{ lib, config, pkgs, ... }:

let
  nix-index-database = (import ../../nix-index-database/packages.nix).${pkgs.stdenv.system}.database;
  packages.${pkgs.stdenv.system} = {
    nix-index-with-db = pkgs.callPackage ../../nix-index-database/nix-index-wrapper.nix {
      inherit nix-index-database;
    };
    comma-with-db = pkgs.callPackage ../../nix-index-database/comma-wrapper.nix {
      inherit nix-index-database;
    };
  };
  legacyPackages.${pkgs.stdenv.system}.database = nix-index-database;
in {
  imports = [
    ((import ../../nix-index-database/home-manager-module.nix) {
      inherit packages legacyPackages;
    })
  ];

  # Provides Bash's command-no-found and a nix-index command:
  programs.nix-index = { enableBashIntegration = true; };
  programs.nix-index-database.comma.enable = true;
}
Mic92 commented 1 year ago

How do you keep this directory up-to-date? Something that uses fetchTarball might be more sustainable.

shoo8eem1A commented 1 year ago

How do you keep this directory up-to-date?

My system's configuration is within a Git repository containing many Git submodules:

At least once a week, I do a git fetch --recurse-submodules, update each module with new commits, and do a home-manager switch. If everything is fine, I commit the result.

If you think a version of the code above should be added to the README, I can adapt it to use a tarball before opening a PR.

Mic92 commented 11 months ago

With https://github.com/nix-community/nix-index-database/pull/81/files we have move part of the module configuration into flake.nix. As such there is no way to use this without using the flake interface.

Mic92 commented 11 months ago

What you can do is importing packages.nix and than create your own nix-index wrapper: https://github.com/nix-community/nix-index-database/blob/main/packages.nix. But I wouldn't consider this an optional, stable interface (also it's not very likely to change any time soon.).

shoo8eem1A commented 10 months ago

@Mic92. I have changed the above snippet to:

{ ... }:

let databases = (import ../../nix-index-database/packages.nix);
in {
  imports = [
    ((import ../../nix-index-database/home-manager-module.nix) {
      inherit databases;
    })
  ];

  # Provides Bash's command-no-found and a nix-index command:
  programs.nix-index = { enableBashIntegration = true; };
  programs.nix-index-database.comma.enable = true;
}

Is there a problem with this approach?

Mic92 commented 10 months ago

@Mic92. I have changed the above snippet to:

{ ... }:

let databases = (import ../../nix-index-database/packages.nix);
in {
  imports = [
    ((import ../../nix-index-database/home-manager-module.nix) {
      inherit databases;
    })
  ];

  # Provides Bash's command-no-found and a nix-index command:
  programs.nix-index = { enableBashIntegration = true; };
  programs.nix-index-database.comma.enable = true;
}

Is there a problem with this approach?

No but you might have to manually upgrade this when we change the implementation.

r-vdp commented 10 months ago

@shoo8eem1A I just merged #86 which means that you won't have to pass the databases manually to the modules anymore.

So when you update, you can leave off that part and just import the module directly.

{
  imports = [
    ../../nix-index-database/home-manager-module.nix
  ];

  programs = { ... };
}
alanpearce commented 4 months ago

Since https://github.com/nix-community/nix-index-database/commit/ca7e10c63d06c7a66d58a1db48b3ba3bd1fd0adf, this no longer works

r-vdp commented 4 months ago

That's unfortunate. Maybe we should restore that functionality, I think it's useful.