We develop two ab initio quantum approaches to thin-film x-ray cavity quantum electrodynamics with spectrally narrow x-ray resonances, such as those provided by Mössbauer nuclei. The first method is based on a few-mode description of the cavity, and promotes and extends existing phenomenological few-mode models to an ab initio theory. The second approach uses analytically-known Green’s functions to model the system. The two approaches not only enable one to ab initio derive the effective few-level scheme representing the cavity and the nuclei in the low-excitation regime, but also provide a direct avenue for studies at higher excitation, involving non-linear or quantum phenomena. The ab initio character of our approaches further enables direct optimizations of the cavity structure and thus of the photonic environment of the nuclei, to tailor the effective quantum optical level scheme towards particular applications. To illustrate the power of the ab initio approaches, we extend the established quantum optical modeling to resonant cavity layers of arbitrary thickness, which is essential to achieve quantitative agreement for cavities used in recent experiments. Further, we consider multi-layer cavities featuring electromagnetically induced transparency, derive their quantum optical few-level systems ab initio, and identify the origin of discrepancies in the modeling found previously using phenomenological approaches as arising from cavity field gradients across the resonant layers.