shrub/nix/lib/dimension.nix
Brendan Hay ce3cbf0857
build: rework all nix expressions to support hercules-ci builds
This also removes nixcrpkgs and OSX cross compilation in favour of
compiling on the target. x86_64/musl targets are still supported
on Linux.

All sources are now managed via niv (see nix/sources.json) and Haskell
package sets are provided/organised via IOHK's haskell.nix.

Some effort has been made to expose similar top-level attributes for
development, but in some cases there have been changes. Please see
the comments in the top-level default.nix and ci.nix files for usage.
2020-10-27 13:55:49 +01:00

111 lines
2.9 KiB
Nix

# From https://github.com/input-output-hk/plutus/blob/99f3a16cdf20e9e78a6105a097956a3773466b14/nix/dimension.nix
{
/* dimension: name -> attrs -> function -> attrs
where
function: keyText -> value -> attrsOf package
WARNING: Attribute names must not contain periods (".").
See https://github.com/NixOS/nix/issues/3088
NOTE: The dimension name will be picked up by agent and web ui soon.
Specifies a dimension of the build matrix. For example
dimension "Example" {
withP = { p = true; }
withoutP = { p = false; }
} (key: # either "withP" or "withoutP"
{ p }: # either p = true or p = false
myProject p
)
evaluates roughly to
{
withP = myProject true;
withoutP = myProject false;
}
Use nested calls for multiple dimensions.
Example:
dimension "System" {
"x86_64-linux" = {};
# ...
}: (system: {}:
dimension "Nixpkgs release" (
{
"nixpkgs-19_03".nixpkgs = someSource
} // optionalAttrs (system != "...") {
"nixpkgs-unstable".nixpkgs = someOtherSource
}
) (_key: { nixpkgs }:
myProject system nixpkgs
)
)
evaluates roughly to
{
x86_64-linux.nixpkgs-19_03 = myProject "x86_64-linux" someSource;
x86_64-linux.nixpkgs-unstable = myProject "x86_64-linux" someOtherSource;
...
}
If you need to make references across attributes, you can do so by binding
the result. Wherever you write
dimension "My dimension" {} (key: value: f1 key value)
You can also write
let
myDimension = dimension "My dimension" {} (key: value: f2 key value myDimension)
in
myDimension
This example builds a single test runner to reuse across releases:
let
overlay =
testRunnerPkgs: self: super: {
# ...
};
myProject =
{ nixpkgs,
pkgs ? import nixpkgs { overlays = [ overlay ]; },
testRunnerPkgs ? pkgs
}: pkgs;
in
let
latest = "nixpkgs-19_03";
releases =
dimension "Nixpkgs release"
{
nixpkgs-18_09.nixpkgs = someSource
nixpkgs-19_03.nixpkgs = someOtherSource
}
(_key: { nixpkgs }:
myProject {
inherit nixpkgs;
testRunnerPkgs = releases."${latest}";
}
);
in releases;
*/
dimension = name: attrs: f:
builtins.mapAttrs (k: v:
let o = f k v;
in o // { recurseForDerivations = o.recurseForDerivations or true; })
attrs // {
meta.dimension.name = name;
};
}