on e304abc help sign in
streamly/default.nix
142 lines 5.6 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.11.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-core =
48 mkPackage super "streamly-core" ./core flags inShell;
49 streamly-benchmarks =
50 mkPackage super "streamly-benchmarks"
51 ./benchmark flags inShell;
52 streamly-tests =
53 mkPackage super "streamly-tests"
54 ./test flags inShell;
55 streamly-docs =
56 mkPackage super "streamly-docs"
57 ./docs flags inShell;
59 #fusion-plugin =
60 # super.callHackageDirect
61 # { pkg = "fusion-plugin";
62 # ver = "0.2.3";
63 # sha256 = "073wbhdxj1sh5160blaihbzkkhabs8s71pqhag16lvmgbb7a3hla";
64 # } {};
66 unicode-data =
67 super.callHackageDirect
68 { pkg = "unicode-data";
69 ver = "0.2.0";
70 sha256 = "14crb68g79yyw87fgh49z2fn4glqx0zr53v6mapihaxzkikhkkc3";
71 } {};
73 tasty-bench = super.tasty-bench_0_3_1;
75 #tasty-bench =
76 # super.callHackageDirect
77 # { pkg = "tasty-bench";
78 # ver = "0.3.1";
79 # sha256 = "0ixdxa7qwl4kck12gwvxg9kydhckjsi5drxcypr33jcdj771j7a4";
80 # } {};
82 #tasty =
83 # super.callHackageDirect
84 # { pkg = "tasty";
85 # ver = "1.4.1";
86 # sha256 = "0g1280gcpcvjbmyk83jv3y9gs2z7fvmcagi9rfs8c9x036nvjq6c";
87 # } {};
89 # Example to Use a different version of a package
90 #QuickCheck = self.QuickCheck_2_14;
92 # Example to disable tests if tests fail or take too long
93 # or to use different configure flags if needed
94 #
95 # XXX We need the ability to disable doCheck on all
96 # those packages that are being built locally and
97 # not fetched from the cache. Running tests could do
98 # nasty things to the machine e.g. some tests even
99 # listen for incoming connections on the network.
100 #selective =
101 # super.selective.overrideAttrs (oldAttrs:
102 # { doCheck = false;
103 # configureFlags =
104 # oldAttrs.configureFlags ++ ["--disable-tests"];
105 # });
106 };
107 };
109 drv = mkHaskellPackages true;
111 shell = drv.shellFor {
112 packages = p:
113 [ p.streamly
114 p.streamly-core
115 p.streamly-benchmarks
116 p.streamly-tests
117 p.streamly-docs
118 ];
119 # some dependencies of hoogle fail to build with quickcheck-2.14
120 # We should use hoogle as external tool instead of building it here
121 # withHoogle = true;
122 doBenchmark = true;
123 # XXX On macOS cabal2nix does not seem to generate a dependency on
124 # Cocoa framework.
125 buildInputs =
126 if builtins.currentSystem == "x86_64-darwin"
127 then [nixpkgs.darwin.apple_sdk.frameworks.Cocoa]
128 else [];
129 # Use a better prompt
130 shellHook = ''
131 export CABAL_DIR="$(pwd)/.cabal.nix"
132 #This is commented for hls to work with VSCode
133 #cabal user-config update -a "jobs: 1"
134 if test -n "$PS_SHELL"
135 then
136 export PS1="$PS_SHELL\[$bldred\](nix:streamly)\[$txtrst\] "
137 fi
138 '';
139 };
140in if nixpkgs.lib.inNixShell
141 then shell
142 else (mkHaskellPackages false).streamly