Skip to content

Commit

Permalink
Merge pull request #37 from matter-labs/recursiveMerge
Browse files Browse the repository at this point in the history
feat: merge the manifest attribute sets better
  • Loading branch information
haraldh authored Jun 7, 2024
2 parents 9fc590a + 7050f3b commit 49a1ae7
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ _:
}:
assert lib.assertMsg (!(isAzure && sgx_default_qcnl_conf != null)) "sgx_default_qcnl_conf can't be set for Azure";
let
manifestRecursiveMerge =
base: mod: with lib.attrsets; let
mergeByPathWithOp = path: action: setAttrByPath path (
if hasAttrByPath path mod
then action (getAttrFromPath path base) (getAttrFromPath path mod)
else getAttrFromPath path base
);
mergeListByPath = path: mergeByPathWithOp path (a: b: a ++ b);
mergeEnvPathByPath = path: mergeByPathWithOp path (a: b: a + ":" + b);
in
recursiveUpdate base (recursiveUpdate mod (
# manually merge the relevant lists / strings
mergeListByPath [ "fs" "mounts" ]
// mergeListByPath [ "sgx" "trusted_files" ]
// mergeEnvPathByPath [ "loader" "env" "LD_LIBRARY_PATH" ]
));
manifest_base = {
libos = { inherit entrypoint; };
fs = {
Expand Down Expand Up @@ -77,7 +93,7 @@ _:
};
};

mergedManifest = (if customRecursiveMerge == null then lib.recursiveUpdate else customRecursiveMerge) manifest_base manifest;
mergedManifest = (if customRecursiveMerge == null then manifestRecursiveMerge else customRecursiveMerge) manifest_base manifest;

tomlFormat = pkgs.formats.toml { };
manifestFile = tomlFormat.generate "${name}.manifest.toml" mergedManifest;
Expand Down

0 comments on commit 49a1ae7

Please sign in to comment.