  We study the moduli functor of flat bundles on smooth, possibly non-proper,
algebraic variety $X$ (over a field of characteristic zero). For this we
introduce the notion of \emph{formal boundary} of $X$, denoted by $\partial X$,
which is a formal analogue of the boundary at infinity of the Betti topological
space associated to $X$. We explain how to construct two derived moduli
functors $Vect^{\nabla}(X)$ and $Vect^{\nabla}(\partial X)$, of flat bundles on
$X$ and on $\partial X$, as well as a restriction map $R : Vect^{\nabla}(X)
\rightarrow Vect^\nabla(\partial X)$ from the former to the later.
  This work contains two main results. First we prove that the morphism R comes
equipped with a canonical shifted Lagrangian structure in the sense of [PTVV].
This first result can be understood as the de Rham analogue of the existence of
Poisson structures on moduli of local systems previously studied by the
authors. As a second statement, we prove that the geometric fibers of $R$ are
representable by "quasi-algebraic spaces", a slight weakening of the notion of
algebraic spaces.
