mirror of
https://github.com/numtide/flake-utils.git
synced 2024-12-14 11:47:31 +00:00
Merge pull request #97 from input-output-hk/jbgi/revert-hydraJobs
Revert special handling of hydraJobs
This commit is contained in:
commit
f9e7cf8183
3 changed files with 72 additions and 41 deletions
56
examples/check-utils/flake.lock
Normal file
56
examples/check-utils/flake.lock
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 0,
|
||||||
|
"narHash": "sha256-omjHh3LT883xERMxVEXH/oeAFI2pAAy30mhZb0eN5G4=",
|
||||||
|
"path": "../..",
|
||||||
|
"type": "path"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"path": "../..",
|
||||||
|
"type": "path"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1685498995,
|
||||||
|
"narHash": "sha256-rdyjnkq87tJp+T2Bm1OD/9NXKSsh/vLlPeqCc/mm7qs=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "9cfaa8a1a00830d17487cb60a19bb86f96f09b27",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"id": "nixpkgs",
|
||||||
|
"type": "indirect"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
|
@ -1,19 +1,28 @@
|
||||||
{
|
{
|
||||||
description = "Flake utils demo";
|
description = "Flake utils demo";
|
||||||
|
|
||||||
inputs.flake-utils.url = "github:numtide/flake-utils";
|
inputs.flake-utils.url = "path:../..";
|
||||||
|
|
||||||
outputs = { self, nixpkgs, flake-utils }:
|
outputs = { self, nixpkgs, flake-utils }:
|
||||||
flake-utils.lib.eachDefaultSystem (system:
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
inherit (flake-utils.lib.check-utils system) isEqual hasKey;
|
inherit (flake-utils.lib.check-utils system) isEqual hasKey;
|
||||||
testDataset = { key1 = "value1"; key2 = 123; key3 = "some>value with^invalid&characters"; };
|
testDataset = { key1 = "value1"; key2 = 123; key3 = "some>value with^invalid&characters"; };
|
||||||
|
mkHydraJobs = system: {
|
||||||
|
toplevel = derivation { name = "toplevel"; builder = "mybuilder"; inherit system; };
|
||||||
|
nested = {
|
||||||
|
attribute = derivation { name = "nested-attribute"; builder = "mybuilder"; inherit system; };
|
||||||
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
rec {
|
rec {
|
||||||
|
hydraJobs = mkHydraJobs system;
|
||||||
checks = {
|
checks = {
|
||||||
# Successful cases
|
# Successful cases
|
||||||
success_isEqual = isEqual testDataset.key1 "value1";
|
success_isEqual = isEqual testDataset.key1 "value1";
|
||||||
success_hasKey = hasKey testDataset "key2";
|
success_hasKey = hasKey testDataset "key2";
|
||||||
|
# ensure no special handling of hydraJobs
|
||||||
|
success_hydraJobs = isEqual self.hydraJobs (flake-utils.lib.eachDefaultSystemMap mkHydraJobs);
|
||||||
|
|
||||||
# Failing cases
|
# Failing cases
|
||||||
failure_isEqual = isEqual testDataset.key1 "failing-data";
|
failure_isEqual = isEqual testDataset.key1 "failing-data";
|
||||||
|
|
46
lib.nix
46
lib.nix
|
@ -26,53 +26,19 @@ let
|
||||||
# eachSystem using defaultSystems
|
# eachSystem using defaultSystems
|
||||||
eachDefaultSystem = eachSystem defaultSystems;
|
eachDefaultSystem = eachSystem defaultSystems;
|
||||||
|
|
||||||
# Builds a map from <attr>=value to <attr>.<system>=value for each system,
|
# Builds a map from <attr>=value to <attr>.<system>=value for each system
|
||||||
# except for the `hydraJobs` attribute, where it maps the inner attributes,
|
|
||||||
# from hydraJobs.<attr>=value to hydraJobs.<attr>.<system>=value.
|
|
||||||
#
|
#
|
||||||
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.
|
# 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:
|
${key} = (attrs.${key} or { })
|
||||||
if key == "hydraJobs"
|
// { ${system} = ret.${key}; };
|
||||||
then (pushDownSystem system (attrs.hydraJobs or { }) ret.hydraJobs)
|
}
|
||||||
else { ${system} = ret.${key}; };
|
|
||||||
in
|
|
||||||
attrs //
|
|
||||||
{
|
|
||||||
${key} = (attrs.${key} or { })
|
|
||||||
// (appendSystem key system ret);
|
|
||||||
}
|
|
||||||
;
|
;
|
||||||
in
|
in
|
||||||
builtins.foldl' op attrs (builtins.attrNames ret);
|
builtins.foldl' op attrs (builtins.attrNames ret);
|
||||||
|
|
Loading…
Reference in a new issue