@@ -1,30 +1,50 @@
1−{ nixpkgs ? import <nixpkgs> {}, compiler ? "default", doBenchmark ? false }:
2−
3−let
4−
5− inherit (nixpkgs) pkgs;
6−
7− f = { mkDerivation, base, bench-show, stdenv, transformers }:
8− mkDerivation {
9− pname = "bench-report";
10− version = "0.0.0";
11− src = ./.;
12− isLibrary = false;
13− isExecutable = true;
14− executableHaskellDepends = [ base bench-show transformers ];
15− description = "Benchmark report generation";
16− license = "unknown";
17− hydraPlatforms = stdenv.lib.platforms.none;
18− };
19−
20− haskellPackages = if compiler == "default"
21− then pkgs.haskellPackages
22− else pkgs.haskell.packages.${compiler};
23−
24− variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;
25−
26− drv = variant (haskellPackages.callPackage f {});
27−
28−in
29−
30− if pkgs.lib.inNixShell then drv.env else drv
1+{
2+ nixpkgs ?
3+ # nixpkgs 21.05 needs a revised version of bench-show and we do not
4+ # know how to use a revised version in nix.
5+ #import (builtins.fetchTarball https://github.com/NixOS/nixpkgs/archive/refs/tags/21.05.tar.gz)
6+ import (builtins.fetchTarball https://github.com/composewell/nixpkgs/archive/01dd2b4e738.tar.gz)
7+ {}
8+#, compiler ? "ghc884" # For nix 21.05
9+, compiler ? "default"
10+}:
11+let haskellPackages =
12+ if compiler == "default"
13+ then nixpkgs.haskellPackages
14+ else nixpkgs.haskell.packages.${compiler};
15+
16+ mkPackage = super: pkg: path: opts: inShell:
17+ let orig = super.callCabal2nixWithOptions pkg path opts {};
18+ in if inShell
19+ # Avoid copying the source directory to nix store by using
20+ # src = null.
21+ then orig.overrideAttrs (oldAttrs: { src = null; })
22+ else orig;
23+
24+ mkHaskellPackages = inShell:
25+ haskellPackages.override {
26+ overrides = self: super:
27+ with nixpkgs.haskell.lib;
28+ {
29+ bench-report = mkPackage super "bench-report" ./. "" inShell;
30+ };
31+ };
32+
33+ drv = mkHaskellPackages true;
34+
35+ shell = drv.shellFor {
36+ packages = p:
37+ [ p.bench-report
38+ ];
39+ # Use a better prompt
40+ shellHook = ''
41+ export CABAL_DIR="$(pwd)/.cabal.nix"
42+ if test -n "$PS_SHELL"
43+ then
44+ export PS1="$PS_SHELL\[$bldred\](nix)\[$txtrst\] "
45+ fi
46+ '';
47+ };
48+in if nixpkgs.lib.inNixShell
49+ then shell
50+ else (mkHaskellPackages false).streamly