on master help sign in
streamly/default.nix
150 lines 6.0 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
9 https://github.com/NixOS/nixpkgs/archive/refs/tags/22.05.tar.gz)
10 {}
11, compiler ? "default"
12, c2nix ? "" # cabal2nix CLI options
13# TODO
14#, sources ? [] # e.g. [./. ./benchmark]
15#, hdeps ? [] # e.g. [time, mtl]
16#, deps ? [] # e.g. [SDL2]
17}:
18let haskellPackages =
19 if compiler == "default"
20 then nixpkgs.haskellPackages
21 else nixpkgs.haskell.packages.${compiler};
23 # we can possibly avoid adding our package to HaskellPackages like
24 # in the case of nix-shell for a single package?
25 mkPackage = super: pkg: path: opts: inShell:
26 let orig = super.callCabal2nixWithOptions pkg path opts {};
27 in if inShell
28 # Avoid copying the source directory to nix store by using
29 # src = null.
30 then orig.overrideAttrs (oldAttrs: { src = null; })
31 else orig;
33 flags = "--benchmark --flag fusion-plugin --flag doctests" + " " + c2nix;
35 mkHaskellPackages = inShell:
36 haskellPackages.override {
37 # We could disbale doCheck on all like this, but it would make the
38 # whole world rebuild, we can't use the binary cache
39 #packageSetConfig = self: super: {
40 # mkDerivation = drv: super.mkDerivation (drv // {
41 # doCheck = false;
42 # });
43 #};
44 overrides = self: super:
45 with nixpkgs.haskell.lib;
46 {
47 streamly = mkPackage super "streamly" ./. flags inShell;
48 streamly-core =
49 mkPackage super "streamly-core" ./core flags inShell;
50 streamly-benchmarks =
51 mkPackage super "streamly-benchmarks"
52 ./benchmark flags inShell;
53 streamly-tests =
54 mkPackage super "streamly-tests"
55 ./test flags inShell;
56 streamly-docs =
57 mkPackage super "streamly-docs"
58 ./docs flags inShell;
60 #fusion-plugin =
61 # super.callHackageDirect
62 # { pkg = "fusion-plugin";
63 # ver = "0.2.3";
64 # sha256 = "073wbhdxj1sh5160blaihbzkkhabs8s71pqhag16lvmgbb7a3hla";
65 # } {};
67 lockfree-queue =
68 super.callHackageDirect
69 { pkg = "lockfree-queue";
70 ver = "0.2.4";
71 sha256 = "1bj9agy3x0yjbscpjgn96gpnj4lvkh39spjvy3jnrr3a42v3ynw7";
72 } {};
74 #unicode-data =
75 # super.callHackageDirect
76 # { pkg = "unicode-data";
77 # ver = "0.2.0";
78 # sha256 = "14crb68g79yyw87fgh49z2fn4glqx0zr53v6mapihaxzkikhkkc3";
79 # } {};
81 #tasty-bench = super.tasty-bench_0_3_1;
83 #tasty-bench =
84 # super.callHackageDirect
85 # { pkg = "tasty-bench";
86 # ver = "0.3.1";
87 # sha256 = "0ixdxa7qwl4kck12gwvxg9kydhckjsi5drxcypr33jcdj771j7a4";
88 # } {};
90 #tasty =
91 # super.callHackageDirect
92 # { pkg = "tasty";
93 # ver = "1.4.1";
94 # sha256 = "0g1280gcpcvjbmyk83jv3y9gs2z7fvmcagi9rfs8c9x036nvjq6c";
95 # } {};
97 # Example to Use a different version of a package
98 #QuickCheck = self.QuickCheck_2_14;
100 # Example to disable tests if tests fail or take too long
101 # or to use different configure flags if needed
102 #
103 # XXX We need the ability to disable doCheck on all
104 # those packages that are being built locally and
105 # not fetched from the cache. Running tests could do
106 # nasty things to the machine e.g. some tests even
107 # listen for incoming connections on the network.
108 #selective =
109 # super.selective.overrideAttrs (oldAttrs:
110 # { doCheck = false;
111 # configureFlags =
112 # oldAttrs.configureFlags ++ ["--disable-tests"];
113 # });
114 };
115 };
117 drv = mkHaskellPackages true;
119 shell = drv.shellFor {
120 packages = p:
121 [ p.streamly
122 p.streamly-core
123 p.streamly-benchmarks
124 p.streamly-tests
125 p.streamly-docs
126 ];
127 # some dependencies of hoogle fail to build with quickcheck-2.14
128 # We should use hoogle as external tool instead of building it here
129 # withHoogle = true;
130 doBenchmark = true;
131 # XXX On macOS cabal2nix does not seem to generate a dependency on
132 # Cocoa framework.
133 buildInputs =
134 if builtins.currentSystem == "x86_64-darwin"
135 then [nixpkgs.darwin.apple_sdk.frameworks.Cocoa]
136 else [];
137 # Use a better prompt
138 shellHook = ''
139 export CABAL_DIR="$(pwd)/.cabal.nix"
140 #This is commented for hls to work with VSCode
141 #cabal user-config update -a "jobs: 1"
142 if test -n "$PS_SHELL"
143 then
144 export PS1="$PS_SHELL\[$bldred\](nix:streamly)\[$txtrst\] "
145 fi
146 '';
147 };
148in if nixpkgs.lib.inNixShell
149 then shell
150 else (mkHaskellPackages false).streamly