Since fleeing Ukraine with her daughter, Iryna Khomich has made a home of a tiny space in a village of prefabricated units in southwestern Germany. A full tour of its single room takes only a few moments: an iron bunk bed and a wardrobe, shoes scattered near the door, clothes drying on radiators. On one recent afternoon, her cat, Dimka, walked in and out, while her daughter, Sofiia, 8, read a German textbook at a desk.

But like other displaced Ukrainians who fled west to wait out the war against Russia, Ms. Khomich, 37, lives each day wrestling with an agonizing choice: Should she return home to Ukraine, where the fighting drags on interminably, or put down roots in Germany, effectively turning a temporary separation into something more lasting?

It is a cruel dilemma faced by countless Ukrainian refugees scattered across Europe as the war nears the end of its second year, one that pits a longing for family and a sense of shared duty to rebuild their shattered country against the realization that the death and destruction are unlikely to end anytime soon. And they are debating it in places like Freiburg, a city nestled on the edge of the Black Forest close to the French border that has offered open arms, an extensive social safety net and the attractive promise of a life without war.

“The heart says go back,” Ms. Khomich said. “But I want the best future for my daughter.”

Germany has been welcoming in its embrace of displaced Ukrainians, hosting 1.2 million currently — along with Poland, the most of any European country. Under a law agreed to by European Union countries in the wake of Russia’s invasion of Ukraine, those Ukrainians have the right to work and live anywhere in the country, and have access to the generous education, health care and social benefits available to ordinary Germans.

Though recently there has been some souring of public opinion toward increased immigration, and all political parties support tightening Germany’s borders, the taking-in of Ukrainians is considered a success. Recently, German leaders have even signaled a desire to offer the refugees a longer-term future in the country.

“Integrate the Ukrainians who are here with us into your companies!” Chancellor Olaf Scholz said in a speech in October, in which he called on German firms to increase hiring.

But while some Ukrainians see a future in Germany, only about a fifth of those of working age are currently employed, according to government statistics, and recent surveys have found that about half still hold out the prospect of going home.

“They are torn,” said Ingrid Braun, a social worker who works with Ukrainians in Freiburg at the village of white, prefabricated units resembling shipping containers, stacked three stories high.

For many of the Ukrainians, the initial journey to Germany led to major cities like Berlin. There, at the decommissioned Tegel airport, about 3,000 are housed by the city in large white halls lined up close to a former runway.

The center was meant to provide a few days of temporary shelter before the refugees moved on, usually to private accommodations in Berlin or beyond. But in a measure of how even Germany’s ability to absorb refugees has limits, some Ukrainians have been living in the small units for a year, their refugee lives calcified into permanence by the lack of affordable housing elsewhere.

Some have been able to find work, in a few cases at a Tesla car factory in Brandenburg, officials said. Others, though, complained that they had not been able to enroll their children in schools without a private address, and that without classes or child care, they were unable to look for work.

Valerie Mykhailova, 25, said she intended to remain in Germany with her daughter, Emily, who just turned 8. Ms. Mykhailova, who is originally from Donetsk, said she had lived with war since she was a teenager, when Russia first invaded the east of Ukraine. Now, though, she has found a boyfriend, a Moroccan man from Kharkiv who lived at the center, and hopes to open a pastry shop in Berlin.

“I very, very much miss Ukraine,” she said, “but I am starting to live my youth.”

From hubs like Tegel, refugees are sent to regional centers like the one in Freiburg, a university town in the relatively wealthy state of Baden-Württemberg. The state is home to more than 100,000 Ukrainian refugees, more than in the whole of France, according to data from Eurostat, the European statistics agency.

Even before the war, Freiburg had strong ties to Ukraine: It is a sister city to Lviv, and when Russia invaded last year, it took in an entire orphanage from Kyiv and its 157 children.

Last year, when conditions in Ukraine appeared to be improving, several hundred refugees who had been living in the city returned home. But at least 2,800 remain, most of them women with children or retirees.

“The first 8, 10, 12 months was more about them waiting and thinking: ‘Then we will go back, we will build a new Ukraine after the war,’” said Freiburg’s mayor, Martin Horn. “But now, they are learning German and looking for a job.”

He acknowledged the wrenching emotional choices involved in the decision to stay, but said that from the city’s perspective the Ukrainians were an asset, capable of filling the city’s work shortages. “We need them,” he said.

To make their integration into the city easier, Freiburg built a welcome center in a former telecoms office in a suburb. The office serves as a kind of brown-brick bureaucratic one-stop-shop, where new arrivals from Ukraine go from desk to desk to sign up for benefits like housing allowances, psychological care, or even a modest cash advance to get them settled.

Children qualify for free public education; more than a half-dozen shared a classroom this fall at the Berthold-Gymnasium, in another part of the city.

“We don’t know if they are going to stay for long or go, so I guess first of all my job is of course to allow them the chance to learn German and also the chance to continue learning at the level they need if they go back,” said Sybille Buske, 52, the school’s principal.

With strong domestic political support for Ukraine’s fight against Russia and for hosting refugees from the country, the current arrangements granting the Ukrainians employment and benefits rights, which currently run to 2025, are expected to be extended. But if the war continues, and the burden on municipal and regional budgets grows, the temporary population may be pressed to integrate more deeply into German society.

Some already have. Anastasiia Matiushchenko, 24, who arrived in Freiburg with her brother, Mykhailo, 19, shortly after the Russian invasion, studied for her German language diploma and now works in a climbing gym. She has rented an apartment and hopes to go to university, and then work for one of the big German companies in nearby Stuttgart.

But even as she gives the impression of an immigrant who has landed on her feet, she cannot be sure that her future lies in Germany. Her husband is barred from leaving Ukraine, because he is of military age. “I think I will go back,” she said. “But I don’t know what’s going to be in Ukraine.”

Out in the industrial suburb of Hochdorf, the village of prefabricated homes houses 145 Ukrainian refugees. On the gravel playground one day this fall, young children participated in a dance lesson while an integration class of 10 women and two men earnestly studied German in a classroom one floor up. Proficiency in the language is often required by companies before seeking jobs or taking other steps into German life.

A teacher, Goetz Baumeister, 78, said that in their practice letters, many of the students wrote about their homesickness. “They want to go back to their grandchildren, their cat, their dog,” he said.

Standing in the door to the small room she has fashioned into a home with her young daughter and their cat, Ms. Khomich weighed her own next move. She said she would like to get a place of her own and a part-time job while she trains to be a pharmacist. She wouldn’t talk about Sofiia’s father, but said that her own father and older sister were still in Ukraine.

“For a lot of people, there is not even the question of whether to stay here or go home, because there is nothing that you can call home,” she said. “If there are safe places, then of course I would consider going back. It is my country and it is also where I was born. It is my blood over there.”