Print the parts, ream the 4mm holes in the guides so the rod slides freely. Drill the 4mm hole in the hat so that it is a tight fit on the rod. You could glue it but I haven't found that necessary. Press fit the two magnets oriented so they attract! Use a low force (e.g. 15gf) microswitch.
Mount as close to the axis of the nozzle as you can get and arrange the rod to be about 5mm above the nozzle tip in the raised position.
Attach a weight sufficient to operate the switch reliably.