In levers and planches, your centre of mass will be directly below the bar or rings. So the minimum about of space needed would be the distance from your centre of mass to the top of your head.
Your centre of mass is usually slightly below your belly button. Let's say 10cm below. Let's also say you want to keep at least a 10cm gap between your head and the wall. You can place the bar the same distance from the wall as your belly button is from the top of your head, plus 20cm.
Or, for an easier way to measure this, measure the height of your belly button from the ground. Assuming you know your own height, the bar distance from the wall can then be calculated as:
Bar distance = 20cm + Your Height - Bellybutton Height
So if you were 170cm tall and your bellybutton is 95cm from the ground, the minimum bar distance would be: 20 + 170 - 95 = 95cm.