nix2container: Layers contains duplicate dependencies
When using layers
results in layers containing multiple identical packages
Example:
{
inputs.nix2container.url = "github:nlewo/nix2container";
inputs.nixpkgs.follows = "nix2container/nixpkgs";
outputs = { self, nixpkgs, nix2container }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
n2c = nix2container.packages.x86_64-linux.nix2container;
in
{
packages.x86_64-linux.default = n2c.buildImage {
maxLayers = 100;
name = "hello";
config = {
entrypoint = [ "${pkgs.hello}/bin/hello" ];
};
layers = [
(n2c.buildLayer {
deps = [ pkgs.bash ];
})
(n2c.buildLayer {
deps = [ pkgs.zsh ];
})
];
};
};
}
Result: glibc (and few other deps) exist in both bash and zsh layers
I noticed there is ignore
option but seems to accept only a single store path. Is there a way to deduplicate derivations?
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 19 (8 by maintainers)
I stumbled upon this problem myself and wrote a little blog post about my fix:
https://blog.eigenvalue.net/2023-nix2container-everything-once/
Maybe it is useful to you or other people discovering this issue!
@kolloch Thank you very much for this post!
(I think it could be linked in this nix2container readme section)
@takeda I have been able to reproduce and i confirm there is an issue. I however didn’t find time yet to dig more (i should be able to in the next 2 weeks). Thx for your example, that’s really useful!
I’ll try to come up with a “smallest breaking example” case and report back 😃
@niklaskorz if my above comment doesn’t help you, do not hesitate to share your issue/usecase.