dockerTools.buildImage how to use apt and install packages

Thank you for the explanation, it makes sense and it’s what I was thinking about it.

My use case is using a single flake for developing, building a docker image and a VM for a test environment. So, a flake with devShells, packages and nixosConfigurations, where the configuration has the build result as virtualisation.oci-containers.containers.<name>.imageFile:

    devShells."${system}".default = pkgs.mkShell {
      ...
    };

    packages."${system}".default = pkgs.dockerTools.buildImage {
      ...
      };

    nixosConfigurations."testVM" = nixpkgs.lib.nixosSystem {
      system = system;
      modules = [
        ...
        {
          virtualisation.docker.enable = true;
          virtualisation.oci-containers.containers."buildResult".imageFile = self.packages."${system}".default;
        }
      ];
    };

But I guess I’m just going to use a VM to build and test the image if there is no easy way to integrate package installation in the buildImage.