Electrons with large kinetic energy have a superconducting instability for infinitesimal attractive interactions. Quenching the kinetic energy and creating a flat band renders an infinitesimal repulsive interaction the relevant perturbation. Thus, flat band systems are an ideal platform to study the competition of superconductivity and magnetism and their possible coexistence. Recent advances in the field of twisted bilayer graphene highlight this in the context of two-dimensional materials. Two dimensions, however, put severe restrictions on the stability of the low-temperature phases due to enhanced fluctuations. Only three-dimensional flat bands can solve the conundrum of combining the exotic flat-band phases with stable order existing at high temperatures. Here, we present a way to generate such flat bands through strain engineering in topological nodal-line semimetals. We present analytical and numerical evidence for this scenario and study the competition of the arising superconducting and magnetic orders as a function of externally controlled parameters. We show that the order parameter is rigid because the quantum geometry of the Bloch wave functions leads to a large superfluid stiffness. Using density-functional theory and numerical tight-binding calculations we further apply our theory to strained rhombohedral graphite and CaAgP materials.