Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 1971f92

Browse files
committed
[nix] Split overlays into their own files
This is a pure refactoring of the nix logic. The primary goal is to modularize the overlays and subsequently make rebasing easier by removing these lines from the `default.nix`.
1 parent 886ba71 commit 1971f92

File tree

7 files changed

+108
-99
lines changed

7 files changed

+108
-99
lines changed

default.nix

+13-99
Original file line numberDiff line numberDiff line change
@@ -29,111 +29,25 @@ with pkgs.lib;
2929
with pkgs.haskell.lib;
3030

3131
let
32-
justStaticExecutablesGitRev = import ./scripts/set-git-rev {
33-
inherit pkgs gitrev;
34-
inherit (cardanoPkgs) ghc;
35-
};
36-
addRealTimeTestLogs = drv: overrideCabal drv (attrs: {
37-
testTarget = "--show-details=streaming";
32+
# the GHC we are using
33+
# at some point use: pkgs.haskell.compiler.ghc843;
34+
ghc = overrideDerivation pkgs.haskell.compiler.ghc822 (drv: {
35+
patches = drv.patches ++ [ ./ghc-8.0.2-darwin-rec-link.patch ];
3836
});
3937

40-
requiredOverlay = self: super: {
41-
inherit pkgs;
42-
srcroot = ./.;
43-
cardano-sl-core = overrideCabal super.cardano-sl-core (drv: {
44-
configureFlags = (drv.configureFlags or []) ++ [
45-
"-f-asserts"
46-
];
47-
});
48-
cardano-sl = overrideCabal super.cardano-sl (drv: {
49-
# production full nodes shouldn't use wallet as it means different constants
50-
configureFlags = (drv.configureFlags or []) ++ [
51-
"-f-asserts"
52-
];
53-
passthru = {
54-
inherit enableProfiling;
55-
};
56-
});
57-
cardano-sl-wallet-static = justStaticExecutablesGitRev self.cardano-sl-wallet;
58-
cardano-sl-client = addRealTimeTestLogs super.cardano-sl-client;
59-
cardano-sl-generator = addRealTimeTestLogs super.cardano-sl-generator;
60-
cardano-sl-networking = addRealTimeTestLogs super.cardano-sl-networking;
61-
cardano-sl-auxx-static = justStaticExecutablesGitRev self.cardano-sl-auxx;
62-
cardano-sl-wallet-new-static = justStaticExecutablesGitRev self.cardano-sl-wallet-new;
63-
cardano-sl-node-static = justStaticExecutablesGitRev self.cardano-sl-node;
64-
cardano-sl-explorer-static = justStaticExecutablesGitRev self.cardano-sl-explorer;
65-
cardano-report-server-static = justStaticExecutablesGitRev self.cardano-report-server;
66-
cardano-sl-faucet-static = justStaticExecutablesGitRev self.cardano-sl-faucet;
67-
cardano-sl-tools-static = justStaticExecutablesGitRev self.cardano-sl-tools;
68-
# Undo configuration-nix.nix change to hardcode security binary on darwin
69-
# This is needed for macOS binary not to fail during update system (using http-client-tls)
70-
# Instead, now the binary is just looked up in $PATH as it should be installed on any macOS
71-
x509-system = overrideDerivation super.x509-system (drv: {
72-
postPatch = ":";
73-
});
74-
75-
# TODO: get rid of pthreads option once cryptonite 0.25 is released
76-
# DEVOPS-393: https://github.com/haskell-crypto/cryptonite/issues/193
77-
cryptonite = appendPatch (appendConfigureFlag super.cryptonite "--ghc-option=-optl-pthread") ./pkgs/cryptonite-segfault-blake.patch;
78-
79-
# Due to https://github.com/input-output-hk/stack2nix/issues/56
80-
hfsevents = self.callPackage ./pkgs/hfsevents.nix { inherit (pkgs.darwin.apple_sdk.frameworks) Cocoa CoreServices; };
81-
mkDerivation = args: super.mkDerivation (args // {
82-
enableLibraryProfiling = enableProfiling;
83-
enableExecutableProfiling = enableProfiling;
84-
# Static linking for everything to work around
85-
# https://ghc.haskell.org/trac/ghc/ticket/14444
86-
# This will be the default in nixpkgs since
87-
# https://github.com/NixOS/nixpkgs/issues/29011
88-
enableSharedExecutables = false;
89-
} // optionalAttrs (args ? src) {
90-
src = localLib.cleanSourceTree args.src;
91-
});
92-
};
93-
benchmarkOverlay = self: super: {
94-
mkDerivation = args: super.mkDerivation (args // optionalAttrs (localLib.isCardanoSL args.pname) {
95-
# Enables building but not running of benchmarks for all
96-
# cardano-sl packages when enableBenchmarks argument is true.
97-
doBenchmark = true;
98-
configureFlags = (args.configureFlags or []) ++ ["--enable-benchmarks"];
99-
} // optionalAttrs (localLib.isBenchmark args) {
100-
# Provide a dummy installPhase for benchmark packages.
101-
installPhase = "mkdir -p $out";
102-
});
103-
};
104-
105-
debugOverlay = self: super: {
106-
mkDerivation = args: super.mkDerivation (args // {
107-
# TODO: DEVOPS-355
108-
dontStrip = true;
109-
configureFlags = (args.configureFlags or []) ++ [ "--ghc-options=-g --disable-executable-stripping --disable-library-stripping" "--profiling-detail=toplevel-functions"];
110-
});
111-
};
112-
38+
# Overlay logic for *haskell* packages.
39+
requiredOverlay = import ./nix/overlays/required.nix pkgs localLib enableProfiling gitrev ghc;
40+
benchmarkOverlay = import ./nix/overlays/benchmark.nix pkgs localLib;
41+
debugOverlay = import ./nix/overlays/debug.nix pkgs;
11342
# Disabling optimization for cardano-sl packages will
11443
# return a build ~20% faster (measured in DEVOPS-1032).
115-
fasterBuildOverlay = self: super: {
116-
mkDerivation = args: super.mkDerivation (args // optionalAttrs (localLib.isCardanoSL args.pname) {
117-
configureFlags = (args.configureFlags or []) ++ [ "--ghc-options=-O0" ];
118-
});
119-
};
120-
121-
dontCheckOverlay = self: super: {
122-
mkDerivation = args: super.mkDerivation (args // {
123-
doCheck = false;
124-
});
125-
};
126-
127-
metricOverlay = self: super: {
128-
mkDerivation = args: super.mkDerivation (args // {
129-
enablePhaseMetrics = true;
130-
});
131-
};
44+
fasterBuildOverlay = import ./nix/overlays/faster-build.nix pkgs localLib;
45+
dontCheckOverlay = import ./nix/overlays/dont-check.nix pkgs;
46+
metricOverlay = import ./nix/overlays/metric.nix pkgs;
13247

48+
# This will yield a set of haskell packages, based on the given compiler.
13349
cardanoPkgsBase = ((import ./pkgs { inherit pkgs; }).override {
134-
ghc = overrideDerivation pkgs.haskell.compiler.ghc822 (drv: {
135-
patches = drv.patches ++ [ ./ghc-8.0.2-darwin-rec-link.patch ];
136-
});
50+
inherit ghc;
13751
});
13852

13953
activeOverlays = [ requiredOverlay ]

nix/overlays/benchmark.nix

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pkgs: localLib: self: super: with pkgs.lib; {
2+
mkDerivation = args: super.mkDerivation (args // optionalAttrs (localLib.isCardanoSL args.pname) {
3+
# Enables building but not running of benchmarks for all
4+
# cardano-sl packages when enableBenchmarks argument is true.
5+
doBenchmark = true;
6+
configureFlags = (args.configureFlags or []) ++ ["--enable-benchmarks"];
7+
} // optionalAttrs (localLib.isBenchmark args) {
8+
# Provide a dummy installPhase for benchmark packages.
9+
installPhase = "mkdir -p $out";
10+
});
11+
}

nix/overlays/debug.nix

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pkgs: self: super: {
2+
mkDerivation = args: super.mkDerivation (args // {
3+
# TODO: DEVOPS-355
4+
dontStrip = true;
5+
configureFlags = (args.configureFlags or []) ++ [ "--ghc-options=-g --disable-executable-stripping --disable-library-stripping" "--profiling-detail=toplevel-functions"];
6+
});
7+
}

nix/overlays/dont-check.nix

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pkgs: self: super: {
2+
mkDerivation = args: super.mkDerivation (args // {
3+
doCheck = false;
4+
});
5+
}

nix/overlays/faster-build.nix

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pkgs: localLib: self: super: {
2+
mkDerivation = args: super.mkDerivation (args // optionalAttrs (localLib.isCardanoSL args.pname) {
3+
configureFlags = (args.configureFlags or []) ++ [ "--ghc-options=-O0" ];
4+
});
5+
}

nix/overlays/metric.nix

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pkgs: self: super: {
2+
mkDerivation = args: super.mkDerivation (args // {
3+
enablePhaseMetrics = true;
4+
});
5+
}

nix/overlays/required.nix

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
pkgs: localLib: enableProfiling: gitrev: ghc:
2+
self: super:
3+
with pkgs.haskell.lib; with pkgs.lib;
4+
let
5+
justStaticExecutablesGitRev = import ../../scripts/set-git-rev {
6+
inherit pkgs gitrev ghc;
7+
};
8+
addRealTimeTestLogs = drv: overrideCabal drv (attrs: {
9+
testTarget = "--show-details=streaming";
10+
});
11+
in {
12+
srcroot = ./.;
13+
cardano-sl-core = overrideCabal super.cardano-sl-core (drv: {
14+
configureFlags = (drv.configureFlags or []) ++ [
15+
"-f-asserts"
16+
];
17+
});
18+
cardano-sl = overrideCabal super.cardano-sl (drv: {
19+
# production full nodes shouldn't use wallet as it means different constants
20+
configureFlags = (drv.configureFlags or []) ++ [
21+
"-f-asserts"
22+
];
23+
passthru = {
24+
inherit enableProfiling;
25+
};
26+
});
27+
cardano-sl-wallet-static = justStaticExecutablesGitRev super.cardano-sl-wallet;
28+
cardano-sl-client = addRealTimeTestLogs super.cardano-sl-client;
29+
cardano-sl-generator = addRealTimeTestLogs super.cardano-sl-generator;
30+
cardano-sl-networking = addRealTimeTestLogs super.cardano-sl-networking;
31+
cardano-sl-auxx-static = justStaticExecutablesGitRev super.cardano-sl-auxx;
32+
cardano-sl-wallet-new-static = justStaticExecutablesGitRev super.cardano-sl-wallet-new;
33+
cardano-sl-node-static = justStaticExecutablesGitRev self.cardano-sl-node;
34+
cardano-sl-explorer-static = justStaticExecutablesGitRev self.cardano-sl-explorer;
35+
cardano-report-server-static = justStaticExecutablesGitRev self.cardano-report-server;
36+
cardano-sl-faucet-static = justStaticExecutablesGitRev self.cardano-sl-faucet;
37+
cardano-sl-tools-static = justStaticExecutablesGitRev super.cardano-sl-tools;
38+
# Undo configuration-nix.nix change to hardcode security binary on darwin
39+
# This is needed for macOS binary not to fail during update system (using http-client-tls)
40+
# Instead, now the binary is just looked up in $PATH as it should be installed on any macOS
41+
x509-system = overrideDerivation super.x509-system (drv: {
42+
postPatch = ":";
43+
});
44+
45+
# TODO: get rid of pthreads option once cryptonite 0.25 is released
46+
# DEVOPS-393: https://github.com/haskell-crypto/cryptonite/issues/193
47+
cryptonite = appendPatch (appendConfigureFlag super.cryptonite "--ghc-option=-optl-pthread") ../../pkgs/cryptonite-segfault-blake.patch;
48+
49+
# Due to https://github.com/input-output-hk/stack2nix/issues/56
50+
hfsevents = self.callPackage ../../pkgs/hfsevents.nix { inherit (pkgs.darwin.apple_sdk.frameworks) Cocoa CoreServices; };
51+
mkDerivation = args: super.mkDerivation (args // {
52+
enableLibraryProfiling = enableProfiling;
53+
enableExecutableProfiling = enableProfiling;
54+
# Static linking for everything to work around
55+
# https://ghc.haskell.org/trac/ghc/ticket/14444
56+
# This will be the default in nixpkgs since
57+
# https://github.com/NixOS/nixpkgs/issues/29011
58+
enableSharedExecutables = false;
59+
} // optionalAttrs (args ? src) {
60+
src = localLib.cleanSourceTree args.src;
61+
});
62+
}

0 commit comments

Comments
 (0)