With Nix, how can I specify Haskell dependencies with profiling enabled?

At first I tried like this:

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

Then the ghc told me

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.

Search the web I found this: https://github.com/NixOS/nixpkgs/issues/22340

So it seems that I cannot load from the cache. But this is normal, if at least I can create profiled options locally.

Can I do it somehow simply by slightly changing the nix expression given -p?

Then at this stage of writing this question, I remembered this resource: https://github.com/NixOS/nixpkgs/blob/bd6ba7/pkgs/development/haskell-modules/lib.nix

Where i found enableLibraryProfiling. So I tried:

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

Which called me to a new error:

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

, enableLibraryProfiling , , , . nix . ? ?

+6
2

nix-repl ElvishJerricco # reflex-frp FreeNode , , , :

$ 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'

+2

, Haskell, Nix. :

Nix . -, ~/.config/nixpkgs/config.nix:

{
  packageOverrides = super: let self = super.pkgs; in
  {
    profiledHaskellPackages = self.haskellPackages.override {
      overrides = self: super: {
        mkDerivation = args: super.mkDerivation (args // {
          enableLibraryProfiling = true;
        });
      };
    };
  };
}

, , profiling-shell.nix:

let nixpkgs = import <nixpkgs> {};
    orig = nixpkgs.pkgs.profiledHaskellPackages.callPackage ./default.nix {};
in (nixpkgs.pkgs.haskell.lib.doBenchmark orig).env

shell.nix, profiledHaskellPackages, . nix-shell profiling-shell.nix . , , . , Nix - nix-shell, , , .

: A nix-collect-garbage -d Nix, , .

, , , . :

  • -prof -fprof-auto GHC
  • default.nix
  • : nix-shell profiling-shell.nix
  • cabal configure --enable-library-profiling --enable-benchmarks
  • cabal build
  • dist/build/projname/projname-bench +RTS -p
  • projname-bench.prof

, , , default.nix Nix.

0

All Articles