substitute: Preserve newlines at the end of file

Newer version of udev require that files contain newlines at the end.
Many of the udev rules use substitute to replace hardcoded binary paths
with nix compatible binaries. Unfortunately, this breaks on the new
version of udev since substitute always strips the newline from the end
of a file it modifies.

This patch fixes the above behavior of substitute, by determining if the
original file had a newline at the end, and appends it to the modified
file.