on 796bb22 help sign in
streamly/default.nix
113 lines 4.4 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# To use ghc-8.6.5
7# nix-shell --argstr compiler "ghc865"
9{
10 nixpkgs ?
11 import (builtins.fetchTarball https://github.com/composewell/nixpkgs/archive/01dd2b4e738.tar.gz)
12 # fusion-plugin is marked as broken
13 { config.allowBroken = true;}
14, compiler ? "default"
15, c2nix ? "" # cabal2nix CLI options
16# TODO
17#, sources ? [] # e.g. [./. ./benchmark]
18#, hdeps ? [] # e.g. [time, mtl]
19#, deps ? [] # e.g. [SDL2]
20}:
21let haskellPackages =
22 if compiler == "default"
23 then nixpkgs.haskellPackages
24 else nixpkgs.haskell.packages.${compiler};
26 # we can possibly avoid adding our package to HaskellPackages like
27 # in the case of nix-shell for a single package?
28 mkPackage = super: pkg: path: opts: inShell:
29 let orig = super.callCabal2nixWithOptions pkg path opts {};
30 in if inShell
31 # Avoid copying the source directory to nix store by using
32 # src = null.
33 then orig.overrideAttrs (oldAttrs: { src = null; })
34 else orig;
36 flags = "--benchmark --flag fusion-plugin --flag doctests" + " " + c2nix;
38 mkHaskellPackages = inShell:
39 haskellPackages.override {
40 # We could disbale doCheck on all like this, but it would make the
41 # whole world rebuild, we can't use the binary cache
42 #packageSetConfig = self: super: {
43 # mkDerivation = drv: super.mkDerivation (drv // {
44 # doCheck = false;
45 # });
46 #};
47 overrides = self: super:
48 with nixpkgs.haskell.lib;
49 {
50 streamly = mkPackage super "streamly" ./. flags inShell;
51 streamly-benchmarks =
52 mkPackage super "streamly-benchmarks"
53 ./benchmark flags inShell;
54 streamly-tests =
55 mkPackage super "streamly-tests"
56 ./test flags inShell;
58 fusion-plugin =
59 super.callHackageDirect
60 { pkg = "fusion-plugin";
61 ver = "0.2.2";
62 sha256 = "1g7j50wa7ffyizv6fdnr09dr4w7bc0hskb46h7y0paw6rh9yz4zj";
63 } {};
65 # Example to Use a different version of a package
66 #QuickCheck = self.QuickCheck_2_14;
68 # Example to disable tests if tests fail or take too long
69 # or to use different configure flags if needed
70 #
71 # XXX We need the ability to disable doCheck on all
72 # those packages that are being built locally and
73 # not fetched from the cache. Running tests could do
74 # nasty things to the machine e.g. some tests even
75 # listen for incoming connections on the network.
76 #selective =
77 # super.selective.overrideAttrs (oldAttrs:
78 # { doCheck = false;
79 # configureFlags =
80 # oldAttrs.configureFlags ++ ["--disable-tests"];
81 # });
82 };
83 };
85 drv = mkHaskellPackages true;
87 shell = drv.shellFor {
88 packages = p:
89 [ p.streamly
90 p.streamly-benchmarks
91 p.streamly-tests
92 ];
93 # some dependencies of hoogle fail to build with quickcheck-2.14
94 # We should use hoogle as external tool instead of building it here
95 # withHoogle = true;
96 doBenchmark = true;
97 # XXX On macOS cabal2nix does not seem to generate a dependency on
98 # Cocoa framework.
99 buildInputs =
100 if builtins.currentSystem == "x86_64-darwin"
101 then [nixpkgs.darwin.apple_sdk.frameworks.Cocoa]
102 else [];
103 # Use a better prompt
104 shellHook = ''
105 if test -n "$PS_SHELL"
106 then
107 export PS1="$PS_SHELL\[$bldred\](nix)\[$txtrst\] "
108 fi
109 '';
110 };
111in if nixpkgs.lib.inNixShell
112 then shell
113 else (mkHaskellPackages false).streamly