Don't do it. Technically yes you can borrow money from your IRA or 401K to use as a down payment or for closing costs, etc. However, if you are under 59.5 yrs. of age, the IRS will tax you on that income and you will have to pay a 10% penalty. So you will need to withdraw more money than what is required because of the taxes and penalty. You will have to check with your employer because your company sets the rules and regulations regarding withdrawals and loans. Also some IRA and 401K take the taxes and penalties up front. Others take it differently.
The other issue is the money you withdraw will lose interest until you replace it. You also need to understand if you lose your job the money withdrawn must be replaced immediately.