I have come to a solution to the first of my issues with a deterministic build in LXC containers: while trying to figure out why the source archive would have a different hash, I noticed that the sort output of the VirtualBox VM would differ from the sort output of the LXC container VM. See this gist.
The solution is fairly simple: instead of sort, use numeric sorting + stable:
sort -n -s
From the man page:
-n, --numeric-sort
compare according to string numerical value
-s, --stable
stabilize sort by disabling last-resort comparison
With my testcase (connecting via ssh and doing a sort) using these 2 options gave me same results on both LXC and VM.
The change needs to be applied to the gitian-linux.yml (and actually everywhere else the sort command is being used!), and yes - it will change the hashes, but for the better of determinism.