Could `foldImageLayers` be added as lib function?
jashandeep-sohi opened this issue · 2 comments
Appreciate the pointer in the readme on how to avoid duplicate files in layers. But could the foldImageLayers
utility function mentioned in that post be included in this flake (or something similar)?
foldImageLayers = let
mergeToLayer = priorLayers: component:
assert builtins.isList priorLayers;
assert builtins.isAttrs component; let
layer = nix2container.buildLayer (component
// {
layers = priorLayers;
});
in
priorLayers ++ [layer];
in
layers: lib.foldl mergeToLayer [] layers;
I find myself duplicating it in multiple projects. Would be easier if it was available upstream.
I agree that this would be great to add and document— as it stands, buildLayer
is a bit of a footgun where you can easily end up re-shipping the same store paths if you're not careful to fold things together in the right way.
As a further enhancement, it would be nice if the layers were nameable/addressable somehow. Basically I have a project with multiple large images that intersect significantly with each other, and I want to define a hierarchy of shared layers upfront (say, A <- B <- C <- D <- E), and then have some of the images include all five, where others include just the first three or four. I know with a list of just a few elements like this I can use numerical slicing, but I'm thinking it will be more like 10-15 in my case, which could get fragile. It would be great to handle this with an API for defining, basically, a "layer set" that then another layer set can build upon.
But could the foldImageLayers utility function mentioned in that post be included in this flake
Yes, a PR would be welcome ;)