Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I search for Haskell packages using "nix search"?

Tags:

haskell

nix

I know that I can search for Haskell packages with nix-env by using

nix-env -f '<nixpkgs>' -qaP -A haskellPackages name_of_package

but that is slow and uncached. If I try to use the new command nix search all the Haskell packages are hidden.

$ nix search aeson
error: no results for the given search term(s)!

Is it possible to search for Haskell packages using the new nix search command? If so, how?


Edit: I found some discussion about this in this irc log, but I couldn't quite grasp what the suggestions would mean in practice. Specifically this part:

20:49 <duairc> How do I make nix search include haskellPackages?
20:52 <ottidmes> duairc: you might try and call recurseIntoAttrs on haskellPackages
20:52 <rain1> thanks
20:52 <LnL> rain1: nix-env -f '<nixpkgs>' -qaP -A haskellPackages
20:54 <gchristensen> duairc: ^
20:54 <duairc> LnL: Thanks!
20:55 <LnL> err, wrong person
20:56 <LnL> you can also add an overlay that recurses, but that might make it
      hard to find non haskell stuff if you're searching for something else
20:56 <ottidmes> I can confirm that
      haskellPackages = super.recurseIntoAttrs super.haskellPackages; works though
20:58 <duairc> ottidmes: What do I do with that expression? Put it in
      configuration.nix somewhere? If I type "nix search ghcid" then
      will it find it?
20:59 <duairc> Ah, you're using super, so I guess it's an overlay
20:59 <clever> duairc: for `nix search` to find it, the overlay must be
      somewhere in $HOME, i forget the exact path
20:59 <clever> duairc: configuration.nix only effects nixos-rebuild and
      nothing else
21:00 <ottidmes> duairc: yeah, it should be put in your overlay that is
      also used by nix-env the like, so not nixpkgs.overlays in your
      configuration.nix as mentioned by clever, and then searching
      for e.g. nix search nix-diff will result in:
      * nixpkgs.haskellPackages.nix-diff (nix-diff)
like image 541
Hjulle Avatar asked Mar 30 '19 12:03

Hjulle


2 Answers

As per the IRC chat, create a ~/.config/nixpkgs/overlays.nix file containing this:

[
  (self: super: {
    haskellPackages = super.recurseIntoAttrs super.haskellPackages;
  })
]

This is an overlay that sets the recurseForDerivations attribute of the haskellPackages set to true. recurseForDerivations tells nix tools to traverse the set, which searches it in the case of nix search. It is currently undocumented, but implemented here.

The Nix wiki describes where to put the overlay and the Nixpkgs manual describes what overlays actually are and how to use them.

like image 190
galagora Avatar answered Oct 12 '22 01:10

galagora


You could save the result of this:

nix-env -f '<nixpkgs>' -qaP -A haskellPackages

And search that output each time instead?

I think the issue is <nixpkgs> will have to be evaluated at each invocation, however if this was a static file/path - it would not need to be.

like image 24
Chris Stryczynski Avatar answered Oct 12 '22 01:10

Chris Stryczynski