  Let $F$ be a $p$-adic field. For certain non-abelian nilpotent algebraic
groups $U$ over $\bar{\mathbb{Z}}_p$ equipped with
$\operatorname{Gal}_F$-action, we study the associated {\it Heisenberg
varieties} which model the non-abelian cohomology set
``$H^1(\operatorname{Gal}_F, U)$''. The construction of Heisenberg varieties
involves the Herr complexes including their cup product structure.
  Write $U_n$ for a quasi-split unitary group and assume $p\ne 2$. We classify
mod $p$ Langlands parameters for $U_n$ (quasi-split),
$\operatorname{SO}_{2n+1}$, $\operatorname{SO}_{2n}$, $\operatorname{Sp}_{2n}$,
$\operatorname{GSpin}_{2m}$ and $\operatorname{GSpin}_{2m+1}$ (split) over $F$,
and show they are successive Heisenberg-type extensions of elliptic Langlands
parameters.
  We employ the Heisenberg variety to study the obstructions for lifting a
non-abelian cocycle along the map $H^1(\operatorname{Gal}_F,
U(\bar{\mathbb{Z}}_p))\to H^1(\operatorname{Gal}_F, U(\bar{\mathbb{F}}_p))$. We
present a precise theorem that reduces the task of finding de Rham lifts of mod
$p$ Langlands parameters for unitary, symplectic, orthogonal, and spin
similitude groups to the dimension analysis of specific closed substacks of the
reduced Emerton-Gee stacks for the corresponding group.
  Finally, we carry out the dimension analysis for the unitary Emerton-Gee
stacks using the geometry of Grassmannian varieties. The paper culminates in
the proof of the existence of potentially crystalline lifts of regular Hodge
type for all mod $p$ Langlands parameters for $p$-adic (possibly ramified)
unitary groups $U_n$. It is the first general existence of de Rham lifts result
for non-split (ramified) groups, and provides evidence for the topological
Breuil-M\'ezard conjecture for more general groups.
