You can then splice on a new piece of wire make sure it is the same wire gauge and run the new piece from the junction box back to the fixture box.
Run wire above ceiling joist no attic.
In some cases you can run the electric wire beneath the ceiling joists.
Worst can you open the ceiling 5 inches from the wall and work from there.
If you drill holes in the joists and run wire through those holes you ll be disturbing the insulation.
A 3 inch strip of drywall is enough to run receptacles around a room.
For vertical work you can cut about 6 inches below the wall ceiling joint drill through the top plat and then fish from the opening ion the ceiling.
Running electrical wire through the channel between ceiling joists is generally easiest.
The actual install of recessed lights here https youtu be 5yc8aqnvqqg the long bit is actually used.
If the wires are within 7 of the attic access hole or along any attic flooring you ll need.
If you have an existing drywall ceiling however or you plan to finish out the ceiling with drywall you must make.
In addition your light fixture may require mounting to a ceiling joist or to two short blocks nailed.