on master help sign in
Add default.nix for nix shell/build
commit8a93c0c6ea0e6c32cdc6cce480d4556699fbff96 authorHarendra Kumar <harendra@composewell.com> dateMon 12 Oct 2020, 03:54 (6 years ago) parent40e8275
2 files changed+104
default.nix+103 streamly.cabal+1
default.nixnew file+103
@@ -0,0 +1,103 @@
1+# CAUTION! a spelling mistake in arg string is ignored silently.
2+#
3+# To include benchmark deps use:
4+# nix-shell --argstr c2nix "--benchmark --flag fusion-plugin"
5+#
6+# To build the chart executable for running bench.sh use:
7+# nix-shell --argstr c2nix "--flag dev" --run "cabal build chart --flag dev"
8+#
9+# To use ghc-8.6.5
10+# nix-shell --argstr compiler "ghc865"
11+
12+{
13+ nixpkgs ?
14+ import (builtins.fetchTarball https://github.com/composewell/nixpkgs/archive/01dd2b4e738.tar.gz)
15+ # fusion-plugin is marked as broken
16+ { config.allowBroken = true;}
17+, compiler ? "default"
18+, c2nix ? "" # cabal2nix CLI options
19+# TODO
20+#, sources ? [] # e.g. [./. ./benchmark]
21+#, hdeps ? [] # e.g. [time, mtl]
22+#, deps ? [] # e.g. [SDL2]
23+}:
24+let haskellPackages =
25+ if compiler == "default"
26+ then nixpkgs.haskellPackages
27+ else nixpkgs.haskell.packages.${compiler};
28+
29+ # we can possibly avoid adding our package to HaskellPackages like
30+ # in the case of nix-shell for a single package?
31+ mkPackage = super: pkg: path: opts: inShell:
32+ let orig = super.callCabal2nixWithOptions pkg path opts {};
33+ in if inShell
34+ # Avoid copying the source directory to nix store by using
35+ # src = null.
36+ then orig.overrideAttrs (oldAttrs: { src = null; })
37+ else orig;
38+
39+ mkHaskellPackages = inShell:
40+ haskellPackages.override {
41+ # We could disbale doCheck on all like this, but it would make the
42+ # whole world rebuild, we can't use the binary cache
43+ #packageSetConfig = self: super: {
44+ # mkDerivation = drv: super.mkDerivation (drv // {
45+ # doCheck = false;
46+ # });
47+ #};
48+ overrides = self: super:
49+ with nixpkgs.haskell.lib;
50+ {
51+ streamly = mkPackage super "streamly" ./. c2nix inShell;
52+ streamly-benchmarks =
53+ mkPackage super "streamly-benchmarks"
54+ ./benchmark c2nix inShell;
55+
56+ # Example to Use a different version of a package
57+ #QuickCheck = self.QuickCheck_2_14;
58+
59+ # Example to disable tests if tests fail or take too long
60+ # or to use different configure flags if needed
61+ #
62+ # XXX We need the ability to disable doCheck on all
63+ # those packages that are being built locally and
64+ # not fetched from the cache. Running tests could do
65+ # nasty things to the machine e.g. some tests even
66+ # listen for incoming connections on the network.
67+ #selective =
68+ # super.selective.overrideAttrs (oldAttrs:
69+ # { doCheck = false;
70+ # configureFlags =
71+ # oldAttrs.configureFlags ++ ["--disable-tests"];
72+ # });
73+ };
74+ };
75+
76+ drv = mkHaskellPackages true;
77+
78+ shell = drv.shellFor {
79+ packages = p:
80+ [ p.streamly
81+ p.streamly-benchmarks
82+ ];
83+ # some dependencies of hoogle fail to build with quickcheck-2.14
84+ # We should use hoogle as external tool instead of building it here
85+ # withHoogle = true;
86+ doBenchmark = true;
87+ # XXX On macOS cabal2nix does not seem to generate a dependency on
88+ # Cocoa framework.
89+ buildInputs =
90+ if builtins.currentSystem == "x86_64-darwin"
91+ then [nixpkgs.darwin.apple_sdk.frameworks.Cocoa]
92+ else [];
93+ # Use a better prompt
94+ shellHook = ''
95+ if test -n "$PS_SHELL"
96+ then
97+ export PS1="$PS_SHELL\[$bldred\](nix)\[$txtrst\] "
98+ fi
99+ '';
100+ };
101+in if nixpkgs.lib.inNixShell
102+ then shell
103+ else (mkHaskellPackages false).streamly
streamly.cabal+1
@@ -134,6 +134,7 @@ extra-source-files:
134134 credits/primitive-0.7.0.0.txt
135135 credits/transient-0.5.5.txt
136136 credits/vector-0.12.0.2.txt
137+ default.nix
137138 design/*.md
138139 design/*.png
139140 design/*.rst