Samples of chert nodules, diagenetic carbonates and evaporites (gypsum/anhydrite) collected from the gypsiferous limestones of the Kef Eddour Member (Ypressian-Priabonian) near Metlaoui and Sehib (Tunisia) show selective silicification with great variety in the silicified by-products. Based on δ13C values, which support an organic origin for the carbon, carbonates replaced evaporites microbially through bacterial sulphate reduction. Observations and results suggest two scenarios for chert formation that are related to the rate and timing of diagenetic carbonate replacement of the evaporites (anhydrite/gypsum). In the absence of early diagenetic carbonate phases, silica with δ18O values from +25 to +28·6‰ [standard mean ocean water (SMOW)] replaced the outer parts of anhydrite nodules at pH < 9. In contrast, pore-fluid pH values > 9 in the innermost parts of the anhydrite nodules prevented silica precipitation. The record of this chemical barrier is preserved in the microquartz rims and geode features that formed in the inner parts of the nodules after dissolution of the anhydrite nucleus. The microbial diagenetic replacement of evaporites (bacterial sulphate reduction) by carbonates (calcite, aragonite and dolomite) favoured silica replacement of carbonates rather than evaporites. Silica, with δ18O signature of +21 to +26‰ (SMOW), replaced carbonates on a volume-for-volume basis, yielding a more siliceous groundmass, and accounting for 90–95% of the nodules. The relatively higher δ18O values of quartz replacing anhydrite can be explained by a diagenetic fluid in equilibrium with mixed (meteoric/marine) to marine water. The lower δ18O values of the quartz that replaced the diagenetic carbonates are ascribed to flushing by meteoric water in a later diagenetic stage. The silica supply for chert formation could be derived from the reworked bio-siliceous deposits (diatomites) to the west of the basin [vestiges of an opal-CT precursor undetectable by X-ray diffraction (XRD) were revealed by δ29Si magic-angle-spinning nuclear magnetic resonance investigations], diagenesis of the extraformational and overlying clay-rich beds (the host limestones are clay-poor as shown by XRD measurements), and minor volcanogenic and hydrothermal contributions during early diagenetic stages.