Skip to content

Commit f7f5c08

Browse files
committed
Make nix-shells functionnal. Run tests on hydra.
1 parent a1572fe commit f7f5c08

File tree

9 files changed

+155
-119
lines changed

9 files changed

+155
-119
lines changed

.buildkite/pipeline.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
steps:
2-
#- label: 'stack rebuild'
3-
# env:
4-
# STACK_ROOT: "/build/cardano-node.stack"
5-
# command:
6-
# - "rm -rf /build/cardano-node"
7-
# - "cp -R . /build/cardano-node"
8-
# - "cd /build/cardano-node"
9-
# - "nix-build scripts/buildkite -o stack-rebuild"
10-
# - "./stack-rebuild"
11-
# agents:
12-
# system: x86_64-linux
2+
- label: 'stack rebuild'
3+
env:
4+
STACK_ROOT: "/build/cardano-node.stack"
5+
command:
6+
- "rm -rf /build/cardano-node"
7+
- "cp -R . /build/cardano-node"
8+
- "cd /build/cardano-node"
9+
- "nix-build scripts/buildkite -o stack-rebuild"
10+
- "./stack-rebuild"
11+
agents:
12+
system: x86_64-linux
1313

1414
- label: 'check-cabal-project'
1515
command: 'nix-build lib.nix -A iohkNix.checkCabalProject -o check-cabal-project.sh && ./check-cabal-project.sh'
1616
agents:
1717
system: x86_64-linux
1818

19+
# FIXME, waiting for https://github.com/input-output-hk/haskell.nix/pull/426
1920
# - label: 'release.nix'
2021
# command: 'nix-build -A check-hydra -o check-hydra.sh && ./check-hydra.sh'
2122
# agents:

cardano-config/cardano-config.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ library
2020
Cardano.Config.Topology
2121
Cardano.Config.Types
2222

23-
build-depends: base >=4.12 && <4.13
23+
build-depends: base >=4.12 && <5
2424
, aeson
2525
, async
2626
, bytestring

default.nix

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{ system ? builtins.currentSystem
22
, crossSystem ? null
33
, config ? {}
4+
, sourcesOverride ? {}
45
, profiling ? false
56
, commonLib ? import ./lib.nix { inherit system crossSystem config profiling; }
67
, pkgs ? commonLib.pkgs
@@ -12,7 +13,7 @@
1213

1314
let
1415
lib = commonLib.pkgs.lib;
15-
inherit (commonLib) environments haskellPackages;
16+
inherit (commonLib) environments haskellPackages niv;
1617
cardano-node = haskellPackages.cardano-node.components.exes.cardano-node;
1718

1819
scripts = commonLib.pkgs.callPackage ./nix/scripts.nix {
@@ -25,7 +26,7 @@ let
2526
};
2627

2728
# we are only intersted in listing the project packages
28-
projectHaskellPackages = pkgs.haskell-nix.haskellLib.selectProjectPackages haskellPackages;
29+
projectHaskellPackages = commonLib.selectProjectPackages haskellPackages;
2930

3031
self = with commonLib; {
3132
inherit scripts nixosTests environments cardano-node;
@@ -34,34 +35,46 @@ let
3435
inherit (iohkNix) check-hydra;
3536

3637
# `tests` are the test suites which have been built.
37-
tests = collectComponents "tests" isCardanoNode haskellPackages;
38-
# `checks` are the result of executing the tests.
39-
checks = pkgs.recurseIntoAttrs (getPackageChecks (filterCardanoPackages haskellPackages));
40-
# `benchmarks` are only built, not run.
41-
benchmarks = collectComponents "benchmarks" isCardanoNode haskellPackages;
38+
tests = collectComponents' "tests" projectHaskellPackages;
39+
# `benchmarks` (only built, not run).
40+
benchmarks = collectComponents' "benchmarks" projectHaskellPackages;
41+
# `checks` collect results of executing the benchmarks and tests:
42+
checks = {
43+
benchmarks = collectChecks self.benchmarks;
44+
tests = collectChecks self.tests;
45+
} // { recurseForDerivations = true; };
4246

4347
shell = haskellPackages.shellFor {
4448

45-
#packages = ps: with ps; [
46-
# haskellPackages.cardano-node
47-
# haskellPackages.cardano-config
48-
#];
49+
packages = ps: with ps; [
50+
ps.cardano-node
51+
ps.cardano-config
52+
# in theory we should only have the above two packages (or better, they should be auto-detected),
53+
# but due to source-repository-package declarations being considered as local packages by cabal, we need the following packages as well.
54+
# cf. https://github.com/haskell/cabal/issues/6249 and https://github.com/haskell/cabal/issues/5444
55+
ps.cardano-sl-x509
56+
ps.ekg-prometheus-adapter
57+
ps.ouroboros-consensus
58+
ps.ouroboros-network
59+
];
4960

5061
# Builds a Hoogle documentation index of all dependencies,
5162
# and provides a "hoogle" command to search the index.
5263
inherit withHoogle;
5364

5465
# You might want some extra tools in the shell (optional).
55-
buildInputs = (with haskellPackages; [
56-
#weeder.components.exes.weeder
57-
#hlint.components.exes.hlint
58-
#cabal-install.components.exes.cabal
59-
#ghcid.components.exes.ghcid
60-
]) ++ (with pkgs; [
66+
buildInputs = with pkgs; [
67+
cabal-install
68+
ghcid
69+
hlint
70+
pkgs.haskellPackages.weeder
71+
nix
72+
niv
6173
pkgconfig
6274
sqlite-interactive
6375
tmux
64-
]);
76+
git
77+
];
6578

6679
# Prevents cabal from choosing alternate plans, so that
6780
# *all* dependencies are provided by Nix.

lib.nix

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,41 @@
22
, crossSystem ? null
33
, config ? {}
44
, overlays ? []
5+
, sourcesOverride ? {}
56
, profiling ? false
67
}:
78

89
let
9-
sources = import ./nix/sources.nix;
10+
# use default stable nixpkgs from iohk-nix instead of our own:
11+
sources = removeAttrs (import ./nix/sources.nix) [ "nixpkgs" ] // sourcesOverride;
1012
iohkNix = import sources.iohk-nix {
13+
inherit config system crossSystem;
1114
sourcesOverride = sources;
15+
nixpkgsOverlays = overlays;
1216
};
13-
haskellNix = import sources."haskell.nix";
14-
args = haskellNix // {
15-
inherit system crossSystem;
16-
overlays = (haskellNix.overlays or []) ++ overlays;
17-
config = (haskellNix.config or {}) // config;
18-
};
19-
nixpkgs = import sources.nixpkgs;
20-
pkgs = nixpkgs args;
17+
pkgs = iohkNix.pkgs;
2118
haskellPackages = import ./nix/pkgs.nix {
2219
inherit pkgs profiling;
2320
src = ./.;
2421
};
2522
# TODO: add haskellPackages and fix svclib
2623
svcLib = import ./nix/svclib.nix { inherit pkgs; cardano-node-packages = haskellPackages.cardano-node.components.exes; };
2724
lib = pkgs.lib;
28-
niv = (import sources.niv {}).niv;
29-
isCardanoNode = with lib; package:
30-
(package.isHaskell or false) &&
31-
((hasPrefix "cardano-node" package.identifier.name) ||
32-
(elem package.identifier.name [ "text-class" "bech32" ]));
33-
filterCardanoPackages = pkgs.lib.filterAttrs (_: package: isCardanoNode package);
34-
getPackageChecks = pkgs.lib.mapAttrs (_: package: package.checks);
25+
26+
collectChecks = lib.mapAttrsRecursiveCond (p: !(lib.isDerivation p))
27+
(_: p: if (lib.isAttrs p) then pkgs.haskell-nix.haskellLib.check p else p);
28+
29+
collectComponents' = group: pkgs.haskell-nix.haskellLib.collectComponents group (_:true);
30+
3531
in lib // iohkNix.cardanoLib // {
36-
inherit (pkgs.haskell-nix.haskellLib) collectComponents;
32+
inherit (pkgs.haskell-nix.haskellLib) collectComponents selectProjectPackages;
33+
inherit (iohkNix) niv;
3734
inherit
38-
niv
3935
sources
4036
haskellPackages
4137
pkgs
4238
iohkNix
4339
svcLib
44-
isCardanoNode
45-
getPackageChecks
46-
filterCardanoPackages;
40+
collectChecks
41+
collectComponents';
4742
}

nix/pkgs.nix

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -20,63 +20,63 @@ let
2020
hasPrefix (toString origSrc + toString dir) path;
2121
} + dir;
2222

23-
recRecurseIntoAttrs = with pkgs; pred: x: if pred x then recurseIntoAttrs (lib.mapAttrs (n: v: if n == "buildPackages" then v else recRecurseIntoAttrs pred v) x) else x;
24-
pkgSet = recRecurseIntoAttrs (x: with pkgs; lib.isAttrs x && !lib.isDerivation x)
25-
# we are only intersted in listing the project packages
26-
(pkgs.lib.filterAttrs (with pkgs.haskell-nix.haskellLib; (n: p: p != null && (isLocalPackage p && isProjectPackage p) || n == "shellFor"))
27-
# from our project which is based on a cabal project.
28-
(pkgs.haskell-nix.cabalProject {
29-
src = pkgs.haskell-nix.haskellLib.cleanGit { inherit src; };
30-
ghc = pkgs.buildPackages.haskell-nix.compiler.${haskellCompiler};
31-
modules = [
32-
# Allow reinstallation of Win32
33-
{ nonReinstallablePkgs =
34-
[ "rts" "ghc-heap" "ghc-prim" "integer-gmp" "integer-simple" "base"
35-
"deepseq" "array" "ghc-boot-th" "pretty" "template-haskell"
36-
# ghcjs custom packages
37-
"ghcjs-prim" "ghcjs-th"
38-
"ghc-boot"
39-
"ghc" "array" "binary" "bytestring" "containers"
40-
"filepath" "ghc-boot" "ghc-compact" "ghc-prim"
41-
# "ghci" "haskeline"
42-
"hpc"
43-
"mtl" "parsec" "text" "transformers"
44-
"xhtml"
45-
# "stm" "terminfo"
46-
];
47-
}
48-
{
49-
# Packages we wish to ignore version bounds of.
50-
# This is similar to jailbreakCabal, however it
51-
# does not require any messing with cabal files.
52-
#doCheck = false;
53-
packages.katip.doExactConfig = true;
54-
packages.ekg.components.library.enableSeparateDataOutput = true;
55-
packages.cardano-node.configureFlags = [ "--ghc-option=-Werror" ];
56-
packages.cardano-node.doCheck = true;
57-
packages.cardano-config.configureFlags = [ "--ghc-option=-Werror" ];
58-
packages.cardano-config.doCheck = true;
59-
enableLibraryProfiling = profiling;
60-
}
61-
(pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isWindows {
62-
# Disable cabal-doctest tests by turning off custom setups
63-
packages.comonad.package.buildType = pkgs.lib.mkForce "Simple";
64-
packages.distributive.package.buildType = pkgs.lib.mkForce "Simple";
65-
packages.lens.package.buildType = pkgs.lib.mkForce "Simple";
66-
packages.nonempty-vector.package.buildType = pkgs.lib.mkForce "Simple";
67-
packages.semigroupoids.package.buildType = pkgs.lib.mkForce "Simple";
23+
pkg-set = pkgs.haskell-nix.cabalProject {
24+
src = pkgs.haskell-nix.haskellLib.cleanGit { inherit src; };
25+
ghc = pkgs.buildPackages.haskell-nix.compiler.${haskellCompiler};
26+
modules = [
6827

69-
# Make sure we use a buildPackages version of happy
70-
packages.pretty-show.components.library.build-tools = [ pkgs.buildPackages.haskell-nix.haskellPackages.happy ];
28+
# Allow reinstallation of Win32
29+
{ nonReinstallablePkgs =
30+
[ "rts" "ghc-heap" "ghc-prim" "integer-gmp" "integer-simple" "base"
31+
"deepseq" "array" "ghc-boot-th" "pretty" "template-haskell"
32+
# ghcjs custom packages
33+
"ghcjs-prim" "ghcjs-th"
34+
"ghc-boot"
35+
"ghc" "array" "binary" "bytestring" "containers"
36+
"filepath" "ghc-boot" "ghc-compact" "ghc-prim"
37+
# "ghci" "haskeline"
38+
"hpc"
39+
"mtl" "parsec" "text" "transformers"
40+
"xhtml"
41+
# "stm" "terminfo"
42+
];
43+
}
44+
{
45+
# Packages we wish to ignore version bounds of.
46+
# This is similar to jailbreakCabal, however it
47+
# does not require any messing with cabal files.
48+
packages.katip.doExactConfig = true;
7149

72-
# Remove hsc2hs build-tool dependencies (suitable version will be available as part of the ghc derivation)
73-
packages.Win32.components.library.build-tools = pkgs.lib.mkForce [];
74-
packages.terminal-size.components.library.build-tools = pkgs.lib.mkForce [];
75-
packages.network.components.library.build-tools = pkgs.lib.mkForce [];
76-
})
77-
];
78-
# TODO add flags to packages (like cs-ledger) so we can turn off tests that will
79-
# not build for windows on a per package bases (rather than using --disable-tests).
80-
configureArgs = pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isWindows "--disable-tests";
81-
}));
82-
in pkgSet
50+
# split data output for ekg to reduce closure size
51+
packages.ekg.components.library.enableSeparateDataOutput = true;
52+
packages.cardano-node.configureFlags = [ "--ghc-option=-Werror" ];
53+
packages.cardano-config.configureFlags = [ "--ghc-option=-Werror" ];
54+
enableLibraryProfiling = profiling;
55+
56+
# some packages are missing identifier.name:
57+
packages.Win32.package.identifier.name = "Win32";
58+
packages.file-embed-lzma.package.identifier.name = "file-embed-lzma";
59+
packages.singletons.package.identifier.name = "singletons";
60+
}
61+
(pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isWindows {
62+
# Disable cabal-doctest tests by turning off custom setups
63+
packages.comonad.package.buildType = pkgs.lib.mkForce "Simple";
64+
packages.distributive.package.buildType = pkgs.lib.mkForce "Simple";
65+
packages.lens.package.buildType = pkgs.lib.mkForce "Simple";
66+
packages.nonempty-vector.package.buildType = pkgs.lib.mkForce "Simple";
67+
packages.semigroupoids.package.buildType = pkgs.lib.mkForce "Simple";
68+
69+
# Make sure we use a buildPackages version of happy
70+
packages.pretty-show.components.library.build-tools = [ pkgs.buildPackages.haskell-nix.haskellPackages.happy ];
71+
72+
# Remove hsc2hs build-tool dependencies (suitable version will be available as part of the ghc derivation)
73+
packages.Win32.components.library.build-tools = pkgs.lib.mkForce [];
74+
packages.terminal-size.components.library.build-tools = pkgs.lib.mkForce [];
75+
packages.network.components.library.build-tools = pkgs.lib.mkForce [];
76+
})
77+
];
78+
# TODO add flags to packages (like cs-ledger) so we can turn off tests that will
79+
# not build for windows on a per package bases (rather than using --disable-tests).
80+
configureArgs = pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isWindows "--disable-tests";
81+
};
82+
in pkg-set

nix/sources.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@
6060
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
6161
},
6262
"iohk-nix": {
63-
"branch": "master",
63+
"branch": "update-nixpkgs-haskell-nix",
6464
"description": "nix scripts shared across projects",
6565
"homepage": null,
6666
"owner": "input-output-hk",
6767
"repo": "iohk-nix",
68-
"rev": "40fc58f0f1cb0f9de24d8df3144a8cd8f2e3a775",
69-
"sha256": "1h3d1gmjfxbwrdszj1ciqlbn646fy687w940fs4gx2bc12j39acb",
68+
"rev": "c8ef22692fa3b1bb1a56205b42a6ce1ba45615cf",
69+
"sha256": "0ark9gjrm3vggryddd55ggdf98q51ww3vqisspczdymjzysws9d4",
7070
"type": "tarball",
71-
"url": "https://github.com/input-output-hk/iohk-nix/archive/40fc58f0f1cb0f9de24d8df3144a8cd8f2e3a775.tar.gz",
71+
"url": "https://github.com/input-output-hk/iohk-nix/archive/c8ef22692fa3b1bb1a56205b42a6ce1ba45615cf.tar.gz",
7272
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
7373
},
7474
"niv": {

nix/stack-shell.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
with import ../lib.nix {};
3+
4+
pkgs.haskell.lib.buildStackProject {
5+
name = "cardano-node-stack-env";
6+
buildInputs = with pkgs; [ zlib openssl gmp libffi git systemd haskellPackages.happy ];
7+
ghc = (import ../shell.nix {}).ghc;
8+
}

release.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ let
104104
# TODO: fix broken evals
105105
#musl64 = mapTestOnCross musl64 (packagePlatformsCross project);
106106
} // extraBuilds // (mkRequiredJob (
107-
collectTests jobs.native.tests ++
107+
collectTests jobs.native.checks.tests ++
108108
collectTests jobs.native.benchmarks ++ [
109109
jobs.native.cardano-node.x86_64-darwin
110110
jobs.native.cardano-node.x86_64-linux

0 commit comments

Comments
 (0)