Hi Anne,
1) You could hammer the nails back in about 1/4″, then spackle, then sand, then PRIME/SEAL, then paint.
2) You could hammer the nails back in about 1/4″, then screw in a drywall screw near the nail, then sand, then PRIME/SEAL, then paint.
Option #1 is the easiest but if you’re planning on doing more work that will work the drywall loose, you’ll be at it a 2nd time. Wait until you’re completely finished the job to do this. Option #2 is the better way to go for a more permanent solution. However, #1 may be just fine. For #2, you’ll need a Dimpler and a Recess attachment for your drill. (Just ask the folks in the Tool Coral for these items.)
My best to ya and hope this helps.
Jay J -Moderator