on c57d6db help sign in
streamly/default.nix
135 lines 5.5 kB history raw
1# CAUTION! a spelling mistake in arg string is ignored silently.
2#
3# To build the chart executable for running bench.sh use:
4# nix-shell --argstr c2nix "--flag dev" --run "cabal build chart --flag dev"
5#
6# You can permanently copy the "chart" executable to "./bin" to pick
7# it up irrespective of the compiler/build. Its path is printed by the
8# above build command. You can also print its path using the following
9# command and then use "cp <path> ./bin" to copy it to "./bin", the bench.sh
10# script will pick it up from there:
11# nix-shell --argstr c2nix "--flag dev" --run "cabal exec --flag dev -- which chart"
13# To use ghc-8.6.5
14# nix-shell --argstr compiler "ghc865"
17 nixpkgs ?
18 import (builtins.fetchTarball https://github.com/NixOS/nixpkgs/archive/refs/tags/21.05.tar.gz)
19 # fusion-plugin is marked as broken
20 { config.allowBroken = true;}
21, compiler ? "default"
22, c2nix ? "" # cabal2nix CLI options
23# TODO
24#, sources ? [] # e.g. [./. ./benchmark]
25#, hdeps ? [] # e.g. [time, mtl]
26#, deps ? [] # e.g. [SDL2]
27}:
28let haskellPackages =
29 if compiler == "default"
30 then nixpkgs.haskellPackages
31 else nixpkgs.haskell.packages.${compiler};
33 # we can possibly avoid adding our package to HaskellPackages like
34 # in the case of nix-shell for a single package?
35 mkPackage = super: pkg: path: opts: inShell:
36 let orig = super.callCabal2nixWithOptions pkg path opts {};
37 in if inShell
38 # Avoid copying the source directory to nix store by using
39 # src = null.
40 then orig.overrideAttrs (oldAttrs: { src = null; })
41 else orig;
43 flags = "--benchmark --flag fusion-plugin --flag doctests" + " " + c2nix;
45 mkHaskellPackages = inShell:
46 haskellPackages.override {
47 # We could disbale doCheck on all like this, but it would make the
48 # whole world rebuild, we can't use the binary cache
49 #packageSetConfig = self: super: {
50 # mkDerivation = drv: super.mkDerivation (drv // {
51 # doCheck = false;
52 # });
53 #};
54 overrides = self: super:
55 with nixpkgs.haskell.lib;
56 {
57 streamly = mkPackage super "streamly" ./. flags inShell;
58 streamly-benchmarks =
59 mkPackage super "streamly-benchmarks"
60 ./benchmark flags inShell;
61 streamly-tests =
62 mkPackage super "streamly-tests"
63 ./test flags inShell;
65 fusion-plugin =
66 super.callHackageDirect
67 { pkg = "fusion-plugin";
68 ver = "0.2.3";
69 sha256 = "073wbhdxj1sh5160blaihbzkkhabs8s71pqhag16lvmgbb7a3hla";
70 } {};
72 tasty-bench =
73 super.callHackageDirect
74 { pkg = "tasty-bench";
75 ver = "0.2.5";
76 sha256 = "052vd87dcik77x6nfbivdibyxyd3byqy4akchr1mrz0hd5ll8apg";
77 } {};
79 tasty =
80 super.callHackageDirect
81 { pkg = "tasty";
82 ver = "1.4.1";
83 sha256 = "0g1280gcpcvjbmyk83jv3y9gs2z7fvmcagi9rfs8c9x036nvjq6c";
84 } {};
86 # Example to Use a different version of a package
87 #QuickCheck = self.QuickCheck_2_14;
89 # Example to disable tests if tests fail or take too long
90 # or to use different configure flags if needed
91 #
92 # XXX We need the ability to disable doCheck on all
93 # those packages that are being built locally and
94 # not fetched from the cache. Running tests could do
95 # nasty things to the machine e.g. some tests even
96 # listen for incoming connections on the network.
97 #selective =
98 # super.selective.overrideAttrs (oldAttrs:
99 # { doCheck = false;
100 # configureFlags =
101 # oldAttrs.configureFlags ++ ["--disable-tests"];
102 # });
103 };
104 };
106 drv = mkHaskellPackages true;
108 shell = drv.shellFor {
109 packages = p:
110 [ p.streamly
111 p.streamly-benchmarks
112 p.streamly-tests
113 ];
114 # some dependencies of hoogle fail to build with quickcheck-2.14
115 # We should use hoogle as external tool instead of building it here
116 # withHoogle = true;
117 doBenchmark = true;
118 # XXX On macOS cabal2nix does not seem to generate a dependency on
119 # Cocoa framework.
120 buildInputs =
121 if builtins.currentSystem == "x86_64-darwin"
122 then [nixpkgs.darwin.apple_sdk.frameworks.Cocoa]
123 else [];
124 # Use a better prompt
125 shellHook = ''
126 export CABAL_DIR="$(pwd)/.cabal.nix"
127 if test -n "$PS_SHELL"
128 then
129 export PS1="$PS_SHELL\[$bldred\](nix)\[$txtrst\] "
130 fi
131 '';
132 };
133in if nixpkgs.lib.inNixShell
134 then shell
135 else (mkHaskellPackages false).streamly