{ nix2container, lib, ... }: rec { baseImage = pkgs: mkImage { inherit pkgs; name = "src.thehellings.com/greg/base"; }; baseLayer = pkgs: with pkgs; rec { copyToRoot = deps; deps = [ (pkgs.buildEnv { name = "base-env"; paths = [ bashInteractive coreutils-full dockerTools.binSh dockerTools.caCertificates dockerTools.shadowSetup dockerTools.usrBinEnv findutils gnugrep gnused ]; }) ]; }; foldLayers = let merge = parents: current: let layer = nix2container.buildLayer ( current // { layers = parents; } ); in parents ++ [ layer ]; in layers: lib.foldl merge [ ] layers; mkImage = pkgs: config: let base = baseLayer pkgs; path = pkgs.lib.makeBinPath (base.deps ++ lib.flatten (builtins.map (e: e.deps) config.layers)); in nix2container.buildImage ( (lib.mergeAttrs { tag = "latest"; config = { Env = [ "PATH=${path}" ]; Cmd = [ "${pkgs.bashInteractive}/bin/bash" ]; }; } config) // { layers = foldLayers ([ base ] ++ config.layers); } ); }