My first question is, how is the Fermi Energy for a material actually determined? I know this derivation, but it seems to say that the Fermi Energy is just based on the electron density (and maybe some effective mass) of the material. Is that really all that determines it?
Secondly, I'm trying to figure out how the interfaces of various materials work in terms of their bands, but it's not clear to me exactly what must be true in all cases (vs what is often but not necessarily true, or what is theoretically but rarely practically true). For example, Anderson's Rule starts by aligning the "vacuum levels" of the two materials, but then this article says that it's not a great idea to use the vacuum level, and the Anderson's Rule article says it's just not that accurate a rule, anyway. Similarly, it seems like the Schottky-Mott Rule isn't very successful either.
Additionally, I've read somewhere that the Fermi Level (the electrochemical potential, the sum of the chemical potential and electric potential) has to be continuous everywhere in both of the materials, so that results in the chemical potentials (i.e., the $T \neq 0$ Fermi Energies, which were normally different in the two materials) lining up, and that happens by having an electric potential difference across them. But this picture from wikipedia then seems to suggest that either what I just said is wrong, or the label should really be "Fermi energy" (or chemical potential) in their definitions. Which is it?
So, what can I always depend on and know is true in these situations?