Neutron star mergers and rare core-collapse supernovae as sources of r-process enrichment in simulated galaxies