In many locations, home electrical work requires a permit and inspection. Ask the local building department if your new light requires one. Purchase the permit before starting the job.
If the attic is small, a single bulb in the center may provide all the light you need. However, if the roofline breaks in two or more directions, consider adding a light for each space.
Use screws to attach the fixtures to the rafters of the roof.
The electrical lines for most homes run through the attic. Tapping into a junction box near the switch or near one of the lights you install is sometimes allowable. Turn off the main circuit breaker before making the tap. If you are adding a light and outlets, consider running a dedicated circuit from the electrical panel.
Attach the wire to the light and switch. Use wire staples to attach the wire to the rafters to avoid creating a trip hazard.
Once the wiring is complete, restore the power and test your work. If you purchased a permit, call for the final inspection.