# May \`nixos-rebuild switch\` terminate a desktop environment session?

**URL:** https://discourse.nixos.org/t/may-nixos-rebuild-switch-terminate-a-desktop-environment-session/65276
**Category:** Help
**Created:** [June 6, 2025, 1:02pm UTC](https://discourse.nixos.org/t/may-nixos-rebuild-switch-terminate-a-desktop-environment-session/65276 "2025-06-06T13:02:00Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![jeltsch](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jeltsch/32/387_2.png) [@jeltsch](https://discourse.nixos.org/u/jeltsch)
#### Post date: [June 6, 2025, 1:02pm UTC](https://discourse.nixos.org/t/may-nixos-rebuild-switch-terminate-a-desktop-environment-session/65276/1 "2025-06-06T13:02:00Z")

</div>

Running `nixos-rebuild switch` restarts services that it has updated. Does this also refer to the login manager and related services? If yes, can restarting such services result in a running desktop environment session (for example, GNOME session) being terminated?

---

<div class="post-metadata">

### Author: ![Kymnd](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/k/c2a13f/32.png) [@Kymnd](https://discourse.nixos.org/u/Kymnd)
#### Post date: [June 6, 2025, 1:21pm UTC](https://discourse.nixos.org/t/may-nixos-rebuild-switch-terminate-a-desktop-environment-session/65276/2 "2025-06-06T13:21:03Z")

</div>

I haven’t been logged out yet, unless I have changed my DE. There are always some services (e.g. gdm.service) which ln not restarted under normal circumstances. But if you are having a critical system, perhaps wait until someone more knowledgable answers your question.

---

<div class="post-metadata">

### Author: ![bme](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@bme](https://discourse.nixos.org/u/bme)
#### Post date: [June 6, 2025, 1:46pm UTC](https://discourse.nixos.org/t/may-nixos-rebuild-switch-terminate-a-desktop-environment-session/65276/3 "2025-06-06T13:46:02Z")

</div>

If you care, use `nixos-rebuild boot` see: [How To: really atomic updates for NixOS - avoiding breakages](https://discourse.nixos.org/t/how-to-really-atomic-updates-for-nixos-avoiding-breakages/63011)

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [June 6, 2025, 3:55pm UTC](https://discourse.nixos.org/t/may-nixos-rebuild-switch-terminate-a-desktop-environment-session/65276/4 "2025-06-06T15:55:44Z")

</div>

It should not. NixOS’s systemd submodule provides `restartIfChanged` to control this, which is set to `false` on things like the `display-manager` service unit. However, if you write a custom service unit that wants/requires an important part of your session (like your display manager), ensure it also has `restartIfChanged = false;` on it.

---

<div class="post-metadata">

### Author: ![Borgvall](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/b/dc4da7/32.png) [@Borgvall](https://discourse.nixos.org/u/Borgvall)
#### Post date: [May 30, 2026, 7:26am UTC](https://discourse.nixos.org/t/may-nixos-rebuild-switch-terminate-a-desktop-environment-session/65276/5 "2026-05-30T07:26:10Z")

</div>

Actually I changed from LightDM to GDM yesterday with `nixos-rebuild switch`. The result was, that LightDM was stopped and my running desktop session terminated. GDM did not show up. Then I restarted the system using TTY.

My expected behavior is, that the switch would have been prohibited or LightDM would have been kept running.

Should I file a bug report? If yes against which module?

---

<div class="post-metadata">

### Author: ![TLATER](https://discourse.nixos.org/user_avatar/discourse.nixos.org/tlater/32/4257_2.png) [@TLATER](https://discourse.nixos.org/u/TLATER)
#### Post date: [May 30, 2026, 10:35am UTC](https://discourse.nixos.org/t/may-nixos-rebuild-switch-terminate-a-desktop-environment-session/65276/6 "2026-05-30T10:35:35Z")

</div>

If you remove the module entirely it has no effect on your system and therefore cannot affect whether it is shut down or not. As far as NixOS is concerned, it does not exist, and never existed to begin with.

Your expected behavior isn’t really realistically feasible without state, which NixOS explicitly avoids.

Just… Don’t regularly switch display managers. You probably won’t switch more than once every few years after your initial experimentation, I don’t think this edge case is worth making our stateless deployment tool stateful.

---

<div class="post-metadata">

### Author: ![codethief](https://discourse.nixos.org/user_avatar/discourse.nixos.org/codethief/32/31696_2.png) [@codethief](https://discourse.nixos.org/u/codethief)
#### Post date: [October 21, 2026, 10:36am UTC](https://discourse.nixos.org/t/may-nixos-rebuild-switch-terminate-a-desktop-environment-session/65276/7 "2026-10-21T10:36:33Z")

</div>

@TLATER (CC @Borgvall)

> As far as NixOS is concerned, it does not exist, and never existed to begin with.

But doesn’t the LightDM unit still exist when `nixos-rebuild --switch` (re-)starts new services & stops old ones? Couldn’t a flag like `X-RestartIfChanged=false` on the unit prevent the teardown? (EDIT: According to Claude, there is already `X-StopOnRemoval=false` to achieve precisely that!)

> Actually I changed from LightDM to GDM yesterday with `nixos-rebuild switch`. The result was, that LightDM was stopped and my running desktop session terminated.

To me this sounds like a bug. Both LightDM and GDM define `display-manager.service` (so switching from LightDM to GDM only changes the existing service) and that one carries `X-RestartIfChanged=false`, so a change shouldn’t trigger a restart. Personally, I’ve never had issues switching display managers.

---

<div class="post-metadata">

### Author: ![TLATER](https://discourse.nixos.org/user_avatar/discourse.nixos.org/tlater/32/4257_2.png) [@TLATER](https://discourse.nixos.org/u/TLATER)
#### Post date: [October 21, 2026, 12:57pm UTC](https://discourse.nixos.org/t/may-nixos-rebuild-switch-terminate-a-desktop-environment-session/65276/8 "2026-10-21T12:57:47Z")

</div>

Yeah, looks like it! [nixpkgs/nixos/doc/manual/development/unit-handling.section.md at 00e46e05ecc785e2469dd4adc4778b7f48b75840 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/blob/00e46e05ecc785e2469dd4adc4778b7f48b75840/nixos/doc/manual/development/unit-handling.section.md)

I assumed these units would be ignored, but clearly the scripts do a more thorough state cleanup. And indeed, the failure could be a bug - I wouldn’t be surprised if a unit not named `display-manager.service` gets restarted and takes the whole thing with it.
