Skip to content

Commit

Permalink
Migrate to overlay style.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbgi committed Feb 7, 2020
1 parent c246276 commit 911e0a8
Show file tree
Hide file tree
Showing 24 changed files with 394 additions and 421 deletions.
2 changes: 1 addition & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ steps:
system: x86_64-linux

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

Expand Down
2 changes: 1 addition & 1 deletion benchmarking/chain-sync/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LOG_CONFIG="$(yj < $BASEDIR/configuration/log-config-ci.yaml)"

CUSTOM_CONFIG="{nodeConfig = builtins.fromJSON ''$LOG_CONFIG'';}"

nix build --out-link ./launch_node -f $BASEDIR/../.. scripts.$CLUSTER.node --arg customConfig "$CUSTOM_CONFIG"
nix build --out-link ./launch_node -f $BASEDIR/../.. scripts.$CLUSTER.node --arg config "{ scriptCustom = $CUSTOM_CONFIG; }"

rm -rf "./state-node-$CLUSTER"

Expand Down
97 changes: 31 additions & 66 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,86 +1,51 @@
{ system ? builtins.currentSystem
, crossSystem ? null
# allows to cutomize haskellNix (ghc and profiling, see ./nix/haskell.nix)
# and scripts (see ./nix/scripts.nix):
, config ? {}
# allows to override dependencies of the project without modifications,
# eg. to test build against local checkout of nixpkgs and iohk-nix:
# nix build -f default.nix cardano-node --arg sourcesOverride '{
# iohk-nix = ../iohk-nix;
# }'
, sourcesOverride ? {}
, profiling ? false
, commonLib ? import ./lib.nix { inherit system crossSystem config profiling; }
, pkgs ? commonLib.pkgs
, customConfig ? {}
, interactive ? false
, gitrev ? commonLib.iohkNix.commitIdFromGitRepoOrZero ./.git
, withHoogle ? true
# pinned version of nixpkgs augmented with overlays (iohk-nix and our packages).
, pkgs ? import ./nix { inherit system crossSystem config sourcesOverride; }
, gitrev ? pkgs.iohkNix.commitIdFromGitRepoOrZero ./.git
}:

with pkgs; with commonLib;
let
lib = commonLib.pkgs.lib;
inherit (commonLib) environments haskellPackages niv;
cardano-node = haskellPackages.cardano-node.components.exes.cardano-node;

scripts = commonLib.pkgs.callPackage ./nix/scripts.nix {
inherit commonLib customConfig;
};
# we are only intersted in listing the project packages
haskellPackages = selectProjectPackages cardanoNodeHaskellPackages;

scripts = callPackage ./nix/scripts.nix {};
# NixOS tests run a proxy and validate it listens
nixosTests = import ./nix/nixos/tests {
inherit (commonLib) pkgs;
inherit commonLib interactive;
inherit pkgs;
};

# we are only intersted in listing the project packages
projectHaskellPackages = commonLib.selectProjectPackages haskellPackages;

self = with commonLib; {
inherit scripts nixosTests environments cardano-node;
self = {
inherit haskellPackages scripts nixosTests environments check-hydra;

haskellPackages = projectHaskellPackages;
inherit (iohkNix) check-hydra;
inherit (haskellPackages.cardano-node.identifier) version;
# Grab the executable component of our package.
inherit (haskellPackages.cardano-node.components.exes)
cardano-node;

# `tests` are the test suites which have been built.
tests = collectComponents' "tests" projectHaskellPackages;
tests = collectComponents' "tests" haskellPackages;
# `benchmarks` (only built, not run).
benchmarks = collectComponents' "benchmarks" projectHaskellPackages;
# `checks` collect results of executing the benchmarks and tests:
benchmarks = collectComponents' "benchmarks" haskellPackages;

checks = {
benchmarks = collectChecks self.benchmarks;
tests = collectChecks self.tests;
# `checks.tests` collect results of executing the tests:
tests = collectChecks haskellPackages;
} // { recurseForDerivations = true; };

shell = haskellPackages.shellFor {

packages = ps: with ps; [
ps.cardano-node
ps.cardano-config
# in theory we should only have the above two packages (or better, they should be auto-detected),
# but due to source-repository-package declarations being considered as local packages by cabal, we need the following packages as well.
# cf. https://github.com/haskell/cabal/issues/6249 and https://github.com/haskell/cabal/issues/5444
ps.cardano-sl-x509
ps.ekg-prometheus-adapter
ps.ouroboros-consensus
ps.ouroboros-network
];

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

# You might want some extra tools in the shell (optional).
buildInputs = with pkgs; [
cabal-install
ghcid
hlint
pkgs.haskellPackages.weeder
nix
niv
pkgconfig
sqlite-interactive
tmux
git
];

# Prevents cabal from choosing alternate plans, so that
# *all* dependencies are provided by Nix.
exactDeps = true;
shell = import ./shell.nix {
inherit pkgs;
withHoogle = true;
};

};

};
in self
42 changes: 0 additions & 42 deletions lib.nix

This file was deleted.

29 changes: 29 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{ system ? builtins.currentSystem
, crossSystem ? null
, config ? {}
, sourcesOverride ? {}
}:
let
# use default stable nixpkgs from iohk-nix instead of our own:
sources = removeAttrs (import ./sources.nix) [ "nixpkgs" ]
// sourcesOverride;

# for inclusion in pkgs:
nixpkgsOverlays = [
(pkgs: _: with pkgs; {

# mix of pkgs.lib with iohk-nix utils and our own:
commonLib = lib // iohkNix // iohkNix.cardanoLib //
import ./util.nix { inherit haskell-nix; };

svcLib = import ./svclib.nix { inherit pkgs; };
})
# Our haskell-nix-ified cabal project:
(import ./pkgs.nix)
];

# IOHK pkgs that include haskell-nix overlays, using our sources as override:
in (import sources.iohk-nix {
inherit system crossSystem config nixpkgsOverlays;
sourcesOverride = sources;
}).pkgs
77 changes: 77 additions & 0 deletions nix/haskell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
############################################################################
# Builds Haskell packages with Haskell.nix
############################################################################
{ lib
, stdenv
, haskell-nix
, buildPackages
, config ? {}
# GHC attribute name
, compiler ? config.haskellNix.compiler or "ghc865"
# Enable profiling
, profiling ? config.haskellNix.profiling or false
}:
let
# GHC attribute name
compiler = config.cardanoNode.compiler or "ghc865";
# Enable profiling
profiling = config.cardanoNode.profiling or false;

# This creates the Haskell package set.
# https://input-output-hk.github.io/haskell.nix/user-guide/projects/
pkgSet = haskell-nix.cabalProject {
src = haskell-nix.haskellLib.cleanGit { src = ../.; };
ghc = buildPackages.haskell-nix.compiler.${compiler};
modules = [

# Allow reinstallation of Win32
{ nonReinstallablePkgs =
[ "rts" "ghc-heap" "ghc-prim" "integer-gmp" "integer-simple" "base"
"deepseq" "array" "ghc-boot-th" "pretty" "template-haskell"
# ghcjs custom packages
"ghcjs-prim" "ghcjs-th"
"ghc-boot"
"ghc" "array" "binary" "bytestring" "containers"
"filepath" "ghc-boot" "ghc-compact" "ghc-prim"
# "ghci" "haskeline"
"hpc"
"mtl" "parsec" "text" "transformers"
"xhtml"
# "stm" "terminfo"
];
}
{
# Packages we wish to ignore version bounds of.
# This is similar to jailbreakCabal, however it
# does not require any messing with cabal files.
packages.katip.doExactConfig = true;

# split data output for ekg to reduce closure size
packages.ekg.components.library.enableSeparateDataOutput = true;
packages.cardano-node.configureFlags = [ "--ghc-option=-Werror" ];
packages.cardano-config.configureFlags = [ "--ghc-option=-Werror" ];
enableLibraryProfiling = profiling;
}
(lib.optionalAttrs stdenv.hostPlatform.isWindows {
# Disable cabal-doctest tests by turning off custom setups
packages.comonad.package.buildType = lib.mkForce "Simple";
packages.distributive.package.buildType = lib.mkForce "Simple";
packages.lens.package.buildType = lib.mkForce "Simple";
packages.nonempty-vector.package.buildType = lib.mkForce "Simple";
packages.semigroupoids.package.buildType = lib.mkForce "Simple";

# Make sure we use a buildPackages version of happy
packages.pretty-show.components.library.build-tools = [ buildPackages.haskell-nix.haskellPackages.happy ];

# Remove hsc2hs build-tool dependencies (suitable version will be available as part of the ghc derivation)
packages.Win32.components.library.build-tools = lib.mkForce [];
packages.terminal-size.components.library.build-tools = lib.mkForce [];
packages.network.components.library.build-tools = lib.mkForce [];
})
];
# TODO add flags to packages (like cs-ledger) so we can turn off tests that will
# not build for windows on a per package bases (rather than using --disable-tests).
configureArgs = lib.optionalString stdenv.hostPlatform.isWindows "--disable-tests";
};
in
pkgSet
2 changes: 1 addition & 1 deletion nix/nixos/cardano-cluster-service.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ in let
### Packages and Nix libs
cardano-node = ncfg.package;
cardano-sl-pkgs = import ccfg.cardano-sl-src { gitrev = ccfg.cardano-sl-src.rev; };
svcLib = (import ../svclib.nix { inherit pkgs; });
svcLib = pkgs.svcLib;

in let
### Node enumeration
Expand Down
6 changes: 3 additions & 3 deletions nix/nixos/cardano-node-service.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

with lib; with builtins;
let
commonLib = import ../../lib.nix {};
localPkgs = import ../. {};
cfg = config.services.cardano-node;
inherit (commonLib) svcLib;
inherit (localPkgs) svcLib commonLib cardanoNodeHaskellPackages;
envConfig = cfg.environments.${cfg.environment}; systemdServiceName = "cardano-node${optionalString cfg.instanced "@"}";
mkScript = cfg:
let exec = "cardano-node run";
Expand Down Expand Up @@ -59,7 +59,7 @@ in {

package = mkOption {
type = types.package;
default = commonLib.haskellPackages.cardano-node.components.exes.cardano-node;
default = cardanoNodeHaskellPackages.cardano-node.components.exes.cardano-node;
defaultText = "cardano-node";
description = ''
The cardano-node package that should be used
Expand Down
6 changes: 3 additions & 3 deletions nix/nixos/chairman-as-a-service.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
, pkgs
, ... }:

with import ../../lib.nix {}; with lib; with builtins;
with pkgs.commonLib; with lib; with builtins;
let
inherit (pkgs) svcLib;
cfg = config.services.chairman;
ncfg = config.services.cardano-node;
chairman = haskellPackages.cardano-node.components.exes.chairman;
svcLib = (import ../svclib.nix { inherit pkgs; });
chairman = pkgs.cardanoNodeHaskellPackages.cardano-node.components.exes.chairman;
envConfig = environments.${cfg.environment};
mkChairmanConfig = nodeConfig: chairmanConfig: {
inherit (nodeConfig) package genesisFile genesisHash stateDir pbftThreshold consensusProtocol;
Expand Down
5 changes: 3 additions & 2 deletions nix/nixos/tests/cardano-node-edge.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{ pkgs, commonLib, ... }:

{ pkgs, ... }:
with pkgs;
{
name = "cardano-node-edge-test";
nodes = {
machine = { config, pkgs, ... }: {
nixpkgs.overlays = pkgsOverlays;
imports = [
../.
];
Expand Down
11 changes: 6 additions & 5 deletions nix/nixos/tests/chairmans-cluster.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{ pkgs
, commonLib
, interactive ? false
, config
, interactive ? config.interactive or false
, ... }:

with pkgs.lib;
let
svcLib = import ../../svclib.nix { pkgs = commonLib.pkgs; };
byron-proxy-src = (import ../../sources.nix).cardano-byron-proxy;
cardano-sl-src = (import ../../sources.nix).cardano-sl;
inherit (pkgs) svcLib pkgsOverlays sources;
byron-proxy-src = sources.cardano-byron-proxy;
cardano-sl-src = sources.cardano-sl;
# byron-proxy-src = ../../../../cardano-byron-proxy;
# cardano-sl-src = ../../../../cardano-sl;
cardano-sl-config = pkgs.runCommand "cardano-sl-config" {} ''
Expand Down Expand Up @@ -35,6 +35,7 @@ in {
name = "chairmans-cluster-test";
nodes = {
machine = { lib, config, pkgs, ... }: {
nixpkgs.overlays = pkgsOverlays;
imports = [
(byron-proxy-src + "/nix/nixos")
../cardano-node-service.nix
Expand Down
Loading

0 comments on commit 911e0a8

Please sign in to comment.