on ec19422 help sign in
streamly/default.nix
106 lines 4.1 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 " + 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 # Example to Use a different version of a package
59 #QuickCheck = self.QuickCheck_2_14;
61 # Example to disable tests if tests fail or take too long
62 # or to use different configure flags if needed
63 #
64 # XXX We need the ability to disable doCheck on all
65 # those packages that are being built locally and
66 # not fetched from the cache. Running tests could do
67 # nasty things to the machine e.g. some tests even
68 # listen for incoming connections on the network.
69 #selective =
70 # super.selective.overrideAttrs (oldAttrs:
71 # { doCheck = false;
72 # configureFlags =
73 # oldAttrs.configureFlags ++ ["--disable-tests"];
74 # });
75 };
76 };
78 drv = mkHaskellPackages true;
80 shell = drv.shellFor {
81 packages = p:
82 [ p.streamly
83 p.streamly-benchmarks
84 p.streamly-tests
85 ];
86 # some dependencies of hoogle fail to build with quickcheck-2.14
87 # We should use hoogle as external tool instead of building it here
88 # withHoogle = true;
89 doBenchmark = true;
90 # XXX On macOS cabal2nix does not seem to generate a dependency on
91 # Cocoa framework.
92 buildInputs =
93 if builtins.currentSystem == "x86_64-darwin"
94 then [nixpkgs.darwin.apple_sdk.frameworks.Cocoa]
95 else [];
96 # Use a better prompt
97 shellHook = ''
98 if test -n "$PS_SHELL"
99 then
100 export PS1="$PS_SHELL\[$bldred\](nix)\[$txtrst\] "
101 fi
102 '';
103 };
104in if nixpkgs.lib.inNixShell
105 then shell
106 else (mkHaskellPackages false).streamly