Skip to content

Commit f8797f4

Browse files
committed
Moves nix-tools standard templates into iohk-nix
As such we can now define: ``` let localLib = import ./lib.nix; in localLib.nix-tools.default-nix ./nix/pkgs.nix ``` as `default.nix` and ``` let localLib = import ./lib.nix; in localLib.nix-tools.release-nix { packages = [ "cardano-chain" "cs-ledger" "small-steps" "cs-blockchain" ]; required-name = "cardano-chain-required-checks"; other-packages = { byronLedgerSpec = import ./specs/ledger/latex {}; byronChainSpec = import ./specs/chain/latex {}; semanticsSpec = import ./specs/semantics/latex {}; }; package-set-path = ./.; } ``` as `release.nix`.
1 parent 7979c9d commit f8797f4

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

default.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ let
5555
regeneratePackages = commonLib.pkgsDefault.callPackage ./nix-tools-regenerate.nix {
5656
nix-tools = package;
5757
};
58+
# default and release templates that abstract
59+
# over the details for CI.
60+
default-nix = import ./nix-tools-default.nix commonLib;
61+
release-nix = import ./nix-tools-release.nix commonLib;
5862
};
5963

6064
stack2nix = rec {

nix-tools-default.nix

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
commonLib: # the iohk-nix commonLib, that provides access to the pinned packages
2+
pkgs-path: # the path to th local pkgs.nix file for nix-tools that imports all
3+
# haskell specific data.
4+
5+
{ system ? builtins.currentSystem
6+
, crossSystem ? null
7+
, config ? {}
8+
, pkgs ? commonLib.getPkgs { inherit system crossSystem config; }
9+
}:
10+
with builtins; with pkgs.lib;
11+
let nix-tools = import pkgs-path { nixpkgs = _: pkgs; };
12+
in {
13+
_lib = commonLib;
14+
15+
# This will allow us to build
16+
# nix-tools.libs.cardano-chain to obtain all libs in a single derivation
17+
# nix-tools.exes.cardano-chain for all executables, same for tests and benchmarks.
18+
#
19+
# The alternative syntax is: nix-tools._raw.cardano-chain.components.$comp
20+
# if you want to build only a single component.
21+
nix-tools = { _raw = nix-tools; }
22+
# some shorthands
23+
// { libs = mapAttrs (k: v: if v ? components && v.components ? "library"
24+
then v.components.library
25+
else null) nix-tools; }
26+
// { exes = mapAttrs (k: v: if (v ? components && length (attrValues v.components.exes) > 0)
27+
then if pkgs.stdenv.targetPlatform.isWindows then pkgs.copyJoin else pkgs.symlinkJoin
28+
{ name = "${k}-exes"; paths = attrValues v.components.exes; }
29+
else null) nix-tools; }
30+
// { tests = mapAttrs (k: v: if v ? components && length (attrValues v.components.tests) > 0
31+
then v.components.tests
32+
else null) nix-tools; }
33+
// { benchmarks = mapAttrs (k: v: if v ? components && length (attrValues v.components.benchmarks) > 0
34+
then v.components.benchmarks
35+
else null) nix-tools; }
36+
;
37+
}

nix-tools-release.nix

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
commonLib: # the iohk-nix commonLib
2+
{ packages ? []
3+
, required-name ? "required"
4+
, other-packages ? {}
5+
, config ? {}
6+
, package-set-path # usually import ./. {}
7+
}:
8+
{ system ? builtins.currentSystem
9+
, pkgs ? commonLib.getPkgs { inherit system config; }
10+
11+
, scrubJobs ? true
12+
, supportedSystems ? [ "x86_64-linux" "x86_64-darwin" ]
13+
, nixpkgsArgs ? {
14+
config = config // { allowUnfree = false; inHydra = true; };
15+
}
16+
}:
17+
with (import (commonLib.nixpkgs + "/pkgs/top-level/release-lib.nix") {
18+
inherit supportedSystems scrubJobs nixpkgsArgs;
19+
packageSet = import package-set-path;
20+
});
21+
with pkgs.lib;
22+
let
23+
24+
25+
traceId = x: builtins.trace (builtins.deepSeq x x) x;
26+
27+
packageSet = import package-set-path {};
28+
nix-tools-pkgs = supportedSystems: {
29+
nix-tools.libs =
30+
mapAttrs (_: _: supportedSystems)
31+
(filterAttrs (n: v: builtins.elem n packages && v != null) packageSet.nix-tools.libs);
32+
nix-tools.exes =
33+
mapAttrs (_: mapAttrs (_: _: supportedSystems))
34+
(filterAttrs (n: v: builtins.elem n packages && v != null) packageSet.nix-tools.exes);
35+
nix-tools.tests =
36+
mapAttrs (_: mapAttrs (_: _: supportedSystems))
37+
(filterAttrs (n: v: builtins.elem n packages && v != null) packageSet.nix-tools.tests);
38+
nix-tools.benchmarks =
39+
mapAttrs (_: mapAttrs (_: _: supportedSystems))
40+
(filterAttrs (n: v: builtins.elem n packages && v != null) packageSet.nix-tools.benchmarks);
41+
};
42+
43+
mapped-pkgs = mapTestOn (nix-tools-pkgs supportedSystems);
44+
mapped-pkgs-mingw32 = mapTestOnCross lib.systems.examples.mingwW64 (nix-tools-pkgs [ "x86_64-linux" ]);
45+
46+
mapped-pkgs-all
47+
= lib.recursiveUpdate
48+
(mapped-pkgs)
49+
(lib.mapAttrs (_: (lib.mapAttrs (_: (lib.mapAttrs' (n: v: lib.nameValuePair (lib.systems.examples.mingwW64.config + "-" + n) v)))))
50+
mapped-pkgs-mingw32);
51+
52+
in fix (self: other-packages // mapped-pkgs-all
53+
// {
54+
# forceNewEval = pkgs.writeText "forceNewEval" chain.rev;
55+
56+
required = pkgs.lib.hydraJob (pkgs.releaseTools.aggregate {
57+
name = required-name;
58+
constituents = with self;
59+
[ # forceNewEval
60+
] ++ builtins.attrNames other-packages
61+
++ map (pkg: [ nix-tools.exes.${pkg}.x86_64-darwin
62+
nix-tools.exes.${pkg}.x86_64-linux
63+
nix-tools.libs.${pkg}.x86_64-darwin
64+
nix-tools.libs.${pkg}.x86_64-linux ]) packages;
65+
# (packages ++ map (pkg: lib.systems.examples.mingwW64.config + "-" + pkg) packages);
66+
});
67+
68+
})

0 commit comments

Comments
 (0)