How to build a constant magnetic field source for a "railgun"?
There is a configuration of two coils, known as a Helmholtz coil, that is supposed to produce a nearly uniform field. The idea is to have two coils that are separated by a distance about the same as the diameter of the individual coils. Going with this, the coil diameter would obviously have to be about the same as the length of your rails, so would be rather large relative to the rest of the apparatus.

But you might not need an exactly uniform field anyway. If you had a field that was non-uniform, but symmetric across a plane that divides the mid-line of your rails, the forces on the movable bar should be in-line. It might be possible to produce a field like that by using two rectangular coils, same width as the rail separation, with one half above the plane of the rails and the other below.