  We study the moduli space of $G_2$-instantons on (projectively) flat bundles
over torsion-free $G_2$-orbifolds. We prove that the moduli space is compact
and smooth at the irreducible locus after adding small and generic holonomy
perturbations. Consequently, we define an integer-valued invariant that is
invariant under $C^0$-deformation of torsion-free $G_2$-structures. We compute
this invariant for some orbifolds that arise in Joyce's construction of compact
$G_2$-manifolds
