Let
X
X
be a locally finite irreducible affine building of dimension
≥
2
\geq 2
, and let
Γ
≤
Aut
(
X
)
\Gamma \leq \operatorname {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
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
X
is of type
A
~
2
\widetilde {A}_2
, then the converse holds. In particular, cocompact lattices in exotic
A
~
2
\widetilde {A}_2
-buildings are nonlinear. As an application, we obtain the first infinite family of lattices in exotic
A
~
2
\widetilde {A}_2
-buildings of arbitrarily large thickness, providing a partial answer to a question of W. Kantor from 1986. We also show that if
X
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
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
X
, which we call the singular Cartan flow.