buildImage is building all the dependencies for the static site into the image. The result of building the static site is a small self contained directory of html, js, and css. In the final output there are no references to anything. Given the nix expr below it produces a large 400MB image.
How can I just get the resulting static files from the “site” derivation below into the image, and not any dependencies used for building it?
{pkgs ? import <nixpkgs> {}}:
let
site = pkgs.mkYarnPackage {
name = "foo";
src = ./.;
packageJSON = ./package.json;
yarnLock = ./yarn.lock;
yarnNix = ./yarn.nix;
buildPhase = "yarn run build";
installPhase = "mkdir -p $out/public/assets; mv deps/foo/build/* $out/public/";
distPhase = "true";
};
staticServerImage = pkgs.dockerTools.buildImage {
name = "foo";
contents = [site];
};
in {
inherit site staticServerImage;
}
I actually have a static binary that I use to serve the files. That doesn’t seem to be the problem as it is only 5MB and building an image with that only builds an image of 5MB. The above example was to demonstrate the minimal example.
A more complete example (including the suggestion of an intermediate derivation)
It doesn’t make a difference if I reference the “site”, or “static-site”, or if I simply include them in contents. All variations seem to include dependencies for building the site.