This significantly improves handling by reducing file size. This is also part of an effort of getting this to build on nix itself.
This is cleaner, and finally enables writing tests for the nix invoking functions.