Isolate dependencies in dedicated layers
masterTo speed up build and push times, you can use the layers attribute in buildImage to specify a set of dependencies that should be isolated. If the dependencies in these layers do not change, the layers are not rebuilt or re-pushed.
Example: Isolating a script from its dependencies
{ pkgs }:
let
application = pkgs.writeScript "conversation" ''
${pkgs.hello}/bin/hello
echo "Haaa aa... I'm dying!!!"
'';
in
pkgs.nix2container.buildImage {
name = "hello";
config = {
entrypoint = ["${pkgs.bash}/bin/bash" application];
};
layers = [
(pkgs.nix2container.buildLayer { deps = [pkgs.bash pkgs.hello]; })
];
}This configuration results in two layers: one containing the bash and hello closures, and a second containing only the script.