I agree with the other points that most companies would not consider your situation if they needed to initiate layoffs but I wouldn't go overboard and just leave without any notice. I think the best way (and what I have done) is try to put myself in their shoes and think "What is a reasonable amount of time that they would need me for?"
Then go to your current boss, explain the situation that you will be leaving but say that you would like to help them with a graceful transition. Then ask him how much time they would need you for still.
If he comes back with something ridiculous like 6 months when you were thinking that 3 weeks would be appropriate then you need to hold firm and counter with your reasons why 3 weeks is appropriate and what you are planning to do in those three weeks to help ease transition.
I think most people would be reasonable at this offer. Unfortunately, there are unreasonable bosses and if they are not budging at 6 months, you need to remember that you have all the leverage. If they make valid points why you should consider staying longer than what you thought, you should take that into account but if they only want to keep you longer because "it would be a hassle" then I would ignore their request.
EDIT: SnOrfus, this is an incredibly subjective answer based on your situation. Your question is lacking enough details to give an appropriate answer.
However, I am in a similar situation so I will give you my input. I am the sole developer on a system that is in production with users yet is still being developed. The company is not a software company. They are building this application as a venture into software and seeing if they can sell it to existing customers. There is no one at the company currently AFAIK that could take over from me in an instant if I left.
If tomorrow, a great opportunity came my way I would probably offer to stay on for about 4 weeks. Here is my reasoning:
- My manager and this place has been great to work for so I would want to repay that as well as I could. If they requested another 2 weeks, I would probably be open to staying for 6 weeks total.
- I think 4 weeks is plenty of time for them to initiate a hiring process and get to the point where they are close to (or already) hiring someone
- 4 weeks would be enough time for me to document anything that is needed for turnover, fix any bugs and complete high priority feature requests
- 4 weeks would hopefully cause some discomfort for them which will give them an opportunity to learn in the future not to solely rely on one person
I don't know you and I assume you are a competent developer otherwise you wouldn't be the sole person on a project. However, in my career I have sometimes overestimated my importance and role to an organization.
Don't worry. Life will go on for them and they will adjust. Look out for yourself.