eachSystem: push down `system` as far down as possible for Hydra jobs (#46)
This commit is contained in:
parent
ad1f7522aa
commit
74f7e43192
38
default.nix
38
default.nix
|
@ -66,15 +66,45 @@ let
|
||||||
#
|
#
|
||||||
eachSystem = systems: f:
|
eachSystem = systems: f:
|
||||||
let
|
let
|
||||||
|
# Taken from <nixpkgs/lib/attrsets.nix>
|
||||||
|
isDerivation = x: builtins.isAttrs x && x ? type && x.type == "derivation";
|
||||||
|
|
||||||
|
# Used to match Hydra's convention of how to define jobs. Basically transforms
|
||||||
|
#
|
||||||
|
# hydraJobs = {
|
||||||
|
# hello = <derivation>;
|
||||||
|
# haskellPackages.aeson = <derivation>;
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# to
|
||||||
|
#
|
||||||
|
# hydraJobs = {
|
||||||
|
# hello.x86_64-linux = <derivation>;
|
||||||
|
# haskellPackages.aeson.x86_64-linux = <derivation>;
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# if the given flake does `eachSystem [ "x86_64-linux" ] { ... }`.
|
||||||
|
pushDownSystem = system: merged:
|
||||||
|
builtins.mapAttrs
|
||||||
|
(name: value:
|
||||||
|
if ! (builtins.isAttrs value) then value
|
||||||
|
else if isDerivation value then (merged.${name} or {}) // { ${system} = value; }
|
||||||
|
else pushDownSystem system (merged.${name} or {}) value);
|
||||||
|
|
||||||
|
# Merge together the outputs for all systems.
|
||||||
op = attrs: system:
|
op = attrs: system:
|
||||||
let
|
let
|
||||||
ret = f system;
|
ret = f system;
|
||||||
op = attrs: key:
|
op = attrs: key:
|
||||||
attrs //
|
let
|
||||||
|
appendSystem = key: system: ret:
|
||||||
|
if key == "hydraJobs"
|
||||||
|
then (pushDownSystem system (attrs.hydraJobs or {}) ret.hydraJobs)
|
||||||
|
else { ${system} = ret.${key}; };
|
||||||
|
in attrs //
|
||||||
{
|
{
|
||||||
${key} = (attrs.${key} or { }) // (if key == "hydraJobs"
|
${key} = (attrs.${key} or { })
|
||||||
then builtins.mapAttrs (name: value: (attrs.hydraJobs.${name} or { }) // { ${system} = value; }) ret.hydraJobs
|
// (appendSystem key system ret);
|
||||||
else { ${system} = ret.${key}; });
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
in
|
in
|
||||||
|
|
Loading…
Reference in New Issue