使用Nix,如何在启用性能分析的情况下指定Haskell依赖项?

Wiz*_*zek 7 haskell nix

我最初是这样尝试的:

nix-shell -p "haskell.packages.ghc821.ghcWithPackages (p: with p; [text hspec lens])" -j4 --run 'ghc Main.hs -prof
Run Code Online (Sandbox Code Playgroud)

然后GHC告诉我

Main.hs:4:1: error:
    Could not find module ‘Control.Lens’
    Perhaps you haven't installed the profiling libraries for package ‘lens-4.15.4’?
    Use -v to see a list of the files searched for.
Run Code Online (Sandbox Code Playgroud)

在网上搜索我发现了这个:https://github.com/NixOS/nixpkgs/issues/22340

所以我似乎无法从缓存中下载.但是没关系,如果至少我可以在本地构建配置文件变体.

我可以通过简单地修改给定的nix表达式以某种方式做到这-p一点吗?

然后在写这个问题的这一点上,我记得这个资源:https://github.com/NixOS/nixpkgs/blob/bd6ba7/pkgs/development/haskell-modules/lib.nix

我找到的地方enableLibraryProfiling.所以我尝试过:

nix-shell -p "haskell.packages.ghc821.ghcWithPackages (p: with p; [text hspec (haskell.lib.enableLibraryProfiling lens)])" -j4 --run 'ghc Main.hs -prof'
Run Code Online (Sandbox Code Playgroud)

这让我遇到了一个新错误:

src/Control/Lens/Internal/Getter.hs:26:1: error:
    Could not find module ‘Data.Functor.Contravariant’
    Perhaps you haven't installed the profiling libraries for package ‘contravariant-1.4’?
    Use -v to see a list of the files searched for.
   |
26 | import Data.Functor.Contravariant
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)

因此,如果我可以将所有包映射到enableLibraryProfiling它们上,那么我想这可行.但是我的nix知识目前并没有完全扩展到那么远.我怎么能这样做?这甚至是正确的追求途径吗?

Wiz*_*zek 3

通过进一步窥探nix-repl以及 ElvishJerricco 在 FreeNode 上 #reflex-frp 上的一些有用的指示,我能够构建这个,这似乎有效:

$ nix-shell -p "(haskell.packages.ghc821.extend (self: super: {mkDerivation = expr: super.mkDerivation (expr // { enableLibraryProfiling = true; });})).ghcWithPackages (p: with p; [text hspec lens])" -j4 --run 'ghc Main.hs -prof'