如何使用"nix search"搜索 Haskell 软件包?



我知道我可以使用 nix-env 搜索 Haskell 软件包

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

但这很慢且未缓存。如果我尝试使用新命令nix search则所有Haskell软件包都将隐藏。

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

是否可以使用新的nix search命令搜索Haskell软件包?如果是这样,如何?


编辑:我在这个irc日志中找到了一些关于这个问题的讨论,但我无法完全理解这些建议在实践中意味着什么。具体来说这部分:

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)

根据IRC聊天,创建一个包含以下内容的~/.config/nixpkgs/overlays.nix文件:

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

这是一个将 haskellPackages 的 recurseForDerivations 属性设置为 true 的叠加层。 recurseForDerivations告诉 nix 工具遍历集合,在nix search的情况下搜索它。它目前没有文档,但在这里实现。

Nix wiki 描述了在哪里放置覆盖层,Nixpkgs 手册描述了覆盖层实际上是什么以及如何使用它们。

您可以保存以下结果:

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

并每次都搜索该输出?

我认为问题是<nixpkgs>必须在每次调用时进行评估,但是如果这是一个静态文件/路径 - 则不需要。

要在 GitHub 上搜索最新消息NixOS/nixpkgs

nix search nixpkgs#haskellPackages PACKAGE_NAME

nix search nixpkgs#haskellPackages aeson

将屈服

* legacyPackages.x86_64-linux.haskellPackages.AesonBson (0.4.1)
  Mapping between Aeson's JSON and Bson objects
* legacyPackages.x86_64-linux.haskellPackages.HsYAML-aeson (0.2.0.1)
  JSON to YAML Adapter
* legacyPackages.x86_64-linux.haskellPackages.Quickson (0.2)
  Quick JSON extractions with Aeson
* legacyPackages.x86_64-linux.haskellPackages.abeson (0.1.0.1)
  interconversion between aeson and bson
* legacyPackages.x86_64-linux.haskellPackages.activitystreams-aeson (0.2.0.2)
  An interface to the ActivityStreams specification
* legacyPackages.x86_64-linux.haskellPackages.aeson (2.1.2.1)
  Fast JSON parsing and encoding
.
.
.

另一个例子

$ nix search nixpkgs#haskellPackages aeson_2  
       
* legacyPackages.x86_64-linux.haskellPackages.aeson_2_2_0_0 (2.2.0.0)
  Fast JSON parsing and encoding

<小时 />

如果您已在本地签出nixpkgs,则为:

nix search .#haskellPackages aeson

最新更新