you can use “nails”, it is called Z-pinning. However, it’s done in dry fiber form with an ultrasonic hammer.
Normally, epoxy, and bolts are normally. Avoid any metal joints that are in direct contact with carbon fiber. Carbon and the metal will form a battery of sorts in presence of humidity, and start to corrode. A way to avoid that is wrap the holes in a glass layer, or coat the bolts with primer. If you are dealing with glass fiber, any bolt will do.
There are pros and cons for each. If the 2 parts are bolted together, it will be weak in shear, and sometimes in compression, especially after impact. That hole will start crack formation and fail starting at the hole. Epoxy can vibrate apart if torsional loads are applied, and the epoxy is more brittle than the composite. However, it is easy, and can sometimes be stronger than a bolt (read: single point loading, vs entire surface bonding). If you want to attach a stiffener to a panel, epoxy should be the way to go as long as you won’t expect major loading.
If using epoxy, you have to prep the surface correctly. You can’t just glue 2 shiny pieces together. Each surface has to he roughened, and cleaned correctly (Acetone WILL leave residue), and the bonding epoxy must be cured correctly. Peelply is a good way to easily achieve good bonding surface. Leave the peelply on the are where you want to bond until you actually have the epoxy ready to glue the parts on.
As Moke mentioned, you can also insert hardpoints in your composite (click-bond is one company), where you make your part WITH a metal fastener inside, be it a bolt or hole. They are prepped to bond well inside your part. Then you can just bolt your 2 parts together nice and easy!
In the end, it depends on what you want to do, what stresses will be placed on the part, how much stress, and part size/assembly limitations.