We demonstrate that a mm-scale free-electron laser can operate in the x-ray range, in the interaction between a moderately relativistic electron bunch, and a transverse high intensity optical lattice. The corrugated light-induced ponderomotive potential acts simultaneously as a guide and as a low-frequency wiggler, triggering stimulated Raman scattering. The gain law in the small signal regime is derived in a fluid approach, and confirmed from particle-in-cell simulations. We describe the nature of bunching, and discuss the saturation properties. The resulting all-optical Raman x-ray laser opens perspectives for ultracompact coherent light sources up to the hard x-ray range.