  Let $X$ be a locally finite irreducible affine building of dimension $\geq 2$
and $\Gamma \leq \mathrm{Aut}(X)$ be a discrete group acting cocompactly. The
goal of this paper is to address the following question: When is $\Gamma$
linear? More generally, when does $\Gamma$ admit a finite-dimensional
representation with infinite image over a commutative unital ring? If $X$ is
the Bruhat--Tits building of a simple algebraic group over a local field and if
$\Gamma$ is an arithmetic lattice, then $\Gamma$ is clearly linear. We prove
that if $X$ is of type $\widetilde A_2$, then the converse holds. In
particular, cocompact lattices in exotic $\widetilde A_2$-buildings are
non-linear. As an application, we obtain the first infinite family of lattices
in exotic $\widetilde A_2$-buildings of arbitrarily large thickness, providing
also a partial answer to a question of W. Kantor from 1986. We also show that
if $X$ is Bruhat--Tits of arbitrary type, then the linearity of $\Gamma$
implies that $\Gamma$ is virtually contained in the linear part of the
automorphism group of $X$, in particular $\Gamma$ is an arithmetic lattice. The
proofs are based on the machinery of algebraic representations of ergodic
systems recently developed by U. Bader and A. Furman. The implementation of
that tool in the present context requires the geometric construction of a
suitable ergodic $\Gamma$-space attached to the the building $X$, which we call
the \emph{singular Cartan flow}.
