It depends on your employers 401k Rules.
Yes, the government created laws which allows for a withdrawal to purchase your first home. But your 401k plan does not need to offer this as a service.
There are also 2 ways of taking the money out:
1) As mentioned before, you can take out the money and repay it into the plan over time (ask you plan manager about what that length of time is)
2) You can take it out and not repay it.
Using a 401k has advantages, such as that you are more easily approved for a mortgage, as you are not touching (or solely relying on) your regular savings or investments for your downpayment. Keeping extra money in these accounts lets the bank know you have money in reserve to pay for unexpected expenses such as repairs to the house, or mortgage payment if you should lose your job and not have a source of income for any period of time.
But beware of some of the pitfalls.
If your plan requires you to repay your loan to the plan, and you decide to move to another company or get fired, you are responsible for coming up with the entire lump sum of what you borrowed within a short period of time (depending on the plan this can be as short as 1-3 months). So if your job isn't 100% stable or if you think you may want to leave anytime soon, going with the 401k is not an option.
Taking money out and not repaying it is not a good thing either.... for some people (myself included) that is their main source of income for retirement. The more money you put in at the begining of the plan, the more time it has to collect interest and grow into a larger sum. Taking out say $50,000 will cost you hundreds of thousands of dollars in lost money 30 years from now.
Although I have a Roth IRA, that won't be enough for retirement. I am thinking about purchasing my first house in 1-2 years, and my 401k will be used. But I will try to do everything in my power not to deplete it just to afford the house.