In Germany (other countries do this differently) the validity of the residence card is based on one of the two following conditions:
how long you are allowed to remain
how long your passport is valid for
whatever is shorter.
As long as you still fullfill all conditions, the Niederlassungserlaubnis is not time limited.
Before your passport expires, you ...
You can apply for a residence permit to stay after graduation. You should start with the application process well before you graduate.
Your university should have a student's council (Allgemeiner Studierendenausschuss, AStA).
Talk to them now. They can advise.
If you are qualified as a programmer, take that as your "Plan B" and not an unskilled job....