Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could foldImageLayers be added as lib function? #108

Open
jashandeep-sohi opened this issue Dec 25, 2023 · 2 comments
Open

Could foldImageLayers be added as lib function? #108

jashandeep-sohi opened this issue Dec 25, 2023 · 2 comments

Comments

@jashandeep-sohi
Copy link

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.

@mikepurvis
Copy link
Contributor

mikepurvis commented Jan 30, 2024

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.

@nlewo
Copy link
Owner

nlewo commented Feb 22, 2024

But could the foldImageLayers utility function mentioned in that post be included in this flake

Yes, a PR would be welcome ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants