Moves the function to a separate file and makes it callPackage-able. Now
that buildEnv also supports finalAttrs, the finalPackage construct can
also be rewritten that way.
This gives us clear separation of concern between the package builder in
generic.nix and wrapper.nix.