on a05abfc help sign in
streamly/default.nix
136 lines 5.4 kB history raw
1# CAUTION! a spelling mistake in arg string is ignored silently.
2#
3# To use ghc-8.6.5
4# nix-shell --argstr compiler "ghc865"
6{
7 nixpkgs ?
8 import (builtins.fetchTarball https://github.com/NixOS/nixpkgs/archive/refs/tags/21.05.tar.gz)
9 {}
10, compiler ? "default"
11, c2nix ? "" # cabal2nix CLI options
12# TODO
13#, sources ? [] # e.g. [./. ./benchmark]
14#, hdeps ? [] # e.g. [time, mtl]
15#, deps ? [] # e.g. [SDL2]
16}:
17let haskellPackages =
18 if compiler == "default"
19 then nixpkgs.haskellPackages
20 else nixpkgs.haskell.packages.${compiler};
22 # we can possibly avoid adding our package to HaskellPackages like
23 # in the case of nix-shell for a single package?
24 mkPackage = super: pkg: path: opts: inShell:
25 let orig = super.callCabal2nixWithOptions pkg path opts {};
26 in if inShell
27 # Avoid copying the source directory to nix store by using
28 # src = null.
29 then orig.overrideAttrs (oldAttrs: { src = null; })
30 else orig;
32 flags = "--benchmark --flag fusion-plugin --flag doctests" + " " + c2nix;
34 mkHaskellPackages = inShell:
35 haskellPackages.override {
36 # We could disbale doCheck on all like this, but it would make the
37 # whole world rebuild, we can't use the binary cache
38 #packageSetConfig = self: super: {
39 # mkDerivation = drv: super.mkDerivation (drv // {
40 # doCheck = false;
41 # });
42 #};
43 overrides = self: super:
44 with nixpkgs.haskell.lib;
45 {
46 streamly = mkPackage super "streamly" ./. flags inShell;
47 streamly-benchmarks =
48 mkPackage super "streamly-benchmarks"
49 ./benchmark flags inShell;
50 streamly-tests =
51 mkPackage super "streamly-tests"
52 ./test flags inShell;
53 streamly-docs =
54 mkPackage super "streamly-docs"
55 ./docs flags inShell;
57 fusion-plugin =
58 super.callHackageDirect
59 { pkg = "fusion-plugin";
60 ver = "0.2.3";
61 sha256 = "073wbhdxj1sh5160blaihbzkkhabs8s71pqhag16lvmgbb7a3hla";
62 } {};
64 unicode-data =
65 super.callHackageDirect
66 { pkg = "unicode-data";
67 ver = "0.2.0";
68 sha256 = "14crb68g79yyw87fgh49z2fn4glqx0zr53v6mapihaxzkikhkkc3";
69 } {};
71 #tasty-bench =
72 # super.callHackageDirect
73 # { pkg = "tasty-bench";
74 # ver = "0.2.5";
75 # sha256 = "052vd87dcik77x6nfbivdibyxyd3byqy4akchr1mrz0hd5ll8apg";
76 # } {};
78 #tasty =
79 # super.callHackageDirect
80 # { pkg = "tasty";
81 # ver = "1.4.1";
82 # sha256 = "0g1280gcpcvjbmyk83jv3y9gs2z7fvmcagi9rfs8c9x036nvjq6c";
83 # } {};
85 # Example to Use a different version of a package
86 #QuickCheck = self.QuickCheck_2_14;
88 # Example to disable tests if tests fail or take too long
89 # or to use different configure flags if needed
90 #
91 # XXX We need the ability to disable doCheck on all
92 # those packages that are being built locally and
93 # not fetched from the cache. Running tests could do
94 # nasty things to the machine e.g. some tests even
95 # listen for incoming connections on the network.
96 #selective =
97 # super.selective.overrideAttrs (oldAttrs:
98 # { doCheck = false;
99 # configureFlags =
100 # oldAttrs.configureFlags ++ ["--disable-tests"];
101 # });
102 };
103 };
105 drv = mkHaskellPackages true;
107 shell = drv.shellFor {
108 packages = p:
109 [ p.streamly
110 p.streamly-benchmarks
111 p.streamly-tests
112 p.streamly-docs
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 cabal user-config update -a "jobs: 1"
128 if test -n "$PS_SHELL"
129 then
130 export PS1="$PS_SHELL\[$bldred\](nix:streamly)\[$txtrst\] "
131 fi
132 '';
133 };
134in if nixpkgs.lib.inNixShell
135 then shell
136 else (mkHaskellPackages false).streamly