(Adds gun-related bills included in spending bill; immigration funding details)
WASHINGTON, March 21 (Reuters) - More money for border security and fighting Russian election hacking was expected to be included in a $1.3 trillion U.S. government spending bill taking shape in Congress on Wednesday, along with gun legislation and a fix to a "grain glitch" in last year's sweeping tax law overhaul.
Congressional leaders laboring to complete the bill face a midnight Friday deadline to avoid a government shutdown.
The measure also will include $10 billion in infrastructure spending for highways, airports and railroads, along with an increase of $2.8 billion to fund opioid addiction treatment, prevention and research, a congressional source said.
Republican and Democratic congressional aides told Reuters that leaders plan to unveil their spending plan on Wednesday.
A senior Republican source said legislation to improve existing background checks on gun buyers would be included in the spending bill, as would a measure to further help schools prevent gun violence.
These steps, following the Feb. 14 mass shooting at a Parkland, Florida, high school and Tuesday's shooting at a school in Maryland, fell short of Democrats' calls for far tougher background checks and banning assault-style weapons.
The spending bill was expected to fund the government through Sept. 30, which would take budget squabbling off the table in the Republican-dominated Congress for the next several months, allowing lawmakers to better focus on their November re-election efforts.
Lawmakers have been arguing since early 2017 about funding for the current fiscal year, which began last Oct. 1. Since then, a series of temporary funding measures have been enacted, but only after two brief government shutdowns occurred because of Congress' inability to pass appropriations bills in a timely way.
House of Representatives Speaker Paul Ryan's communications office issued a statement saying the legislation had been finalized but full details were not yet made public.
"We do have a few language points that need to clear up but we have made good progress," House Democratic Leader Nancy Pelosi said in a statement.
Without action by Congress, temporary funding for some agencies and programs would expire at midnight on Friday.
One last-minute hang-up resolved on Wednesday was fixing a mistake in the sweeping tax law overhaul approved by Republicans in December that gave lucrative tax breaks to grain producers selling to farming cooperatives and a lesser break for selling to agriculture companies. Grain purchasers such as Anheuser Busch, Cargill and the ethanol industry said that said it put them at a disadvantage.
The "grain glitch" fix will be in the spending bill, along with a bipartisan proposal to expand a low-income housing tax credit requested by Democrats, according to multiple aides.
Negotiations were prolonged by a dispute over President Donald Trump's proposed border wall. So far, the package provides $1.6 billion for some fencing along the U.S. border with Mexico and other technological border security efforts, the source said.
Trump wanted $25 billion for his wall but negotiations fell through to provide more money in exchange for protections for "Dreamers," young adults brought illegally into the United States as children.
Trump also failed to get the money he wanted for additional immigrant detention center beds and agents to carry out his goal of deporting more undocumented people, according to one source familiar with the negotiations.
Additionally, the plan provides $307 million more than Trump requested for the FBI to counter Russian cyber attacks and $380 million for U.S. states to improve voting technology before November's congressional election, according to the source.
U.S. intelligence agencies have said Russia tried to interfere in the 2016 presidential election campaign and will try again this year. Russia has denied any meddling.
If approved by the full House and Senate, the bill would fund the biggest U.S. defense buildup in 15 years.
It also would allocate $10 billion for highways, airports, railroads and high-speed broadband, including money for the so-called Gateway rail tunnel connecting New York and New Jersey, the source said, despite a veto threat by Trump.
Also added was $2.8 billion to fight opioid addiction and $2 billion for military veteran health facilities, the source said. (Additional reporting by Susan Heavey, Lisa Lambert Editing by Kevin Drawbaugh and Bill Trott)