summary refs log tree commit diff
path: root/nixos/modules/config
diff options
context:
space:
mode:
authorrnhmjoj <rnhmjoj@inventati.org>2021-02-20 16:07:38 +0100
committerrnhmjoj <rnhmjoj@inventati.org>2021-02-21 10:27:34 +0100
commit9be052921004f45a34af2e7a42bd88078b480502 (patch)
tree7f8c7d2d1b823e841313e084cc18c56ed543883f /nixos/modules/config
parenta2bbdf6ec69349846f9de591ccdfcc0118dad1d4 (diff)
downloadnixpkgs-9be052921004f45a34af2e7a42bd88078b480502.tar
nixpkgs-9be052921004f45a34af2e7a42bd88078b480502.tar.gz
nixpkgs-9be052921004f45a34af2e7a42bd88078b480502.tar.bz2
nixpkgs-9be052921004f45a34af2e7a42bd88078b480502.tar.lz
nixpkgs-9be052921004f45a34af2e7a42bd88078b480502.tar.xz
nixpkgs-9be052921004f45a34af2e7a42bd88078b480502.tar.zst
nixpkgs-9be052921004f45a34af2e7a42bd88078b480502.zip
nixos/console: fix console setting reloading
It's a dull and boring day, it's cold outside and I'm stuck at home: let
me tell you the story of systemd-vconsole-setup.

In the beginnings of NixOS[1], systemd-vconsole-setup was a powerful
sysinit.target unit, installed and running at boot to set up fonts
keyboard layouts and even colors of the virtual consoles. If needed, the
service would also be restarted after a configuration change, consoles
were happy and everything was good, well, almost.

Since the service had no way to specify the dependency "ttys are ready",
modesetting could sometimes happen *after* systemd-vconsole-setup had
started, leaving the console in a broken state. So abbradar worked
around that by putting a systemd-udev-settle `After=`.

In the meanwhile, probably realizing their mistake, systemd added a
shiny udev rule to start the systemd-udev-settle at the right time[2].
However, the rule bypassed systemd by directly running the binary
`systemd-udev-settle`, and the service - though still installed - fell
into disuse.

Two years would pass before a good samaritan, seeing the poor jobless
systemd-udev-settle service, decided to give it the coup de grĂ¢s[3] by
unlisting it from the installed units.
This, combined with another bug, caused quite a commotion[4] in NixOS;
to see why remember the fact that `WantedBy=` in upstream units doesn't
work[5], so it had to be added manually in cc542110, but while systemd
removed it, the NixOS unit continued to install and restart the service,
making a lot of fuss when switching configuration.

After at least thee different tentative fixes, deedrah realised[6] what
the root cause was and fpletz put the final nail[7] in the coffin of
systemd-udev-settle. The service would never see the light of a boot
again, NixOS would not restart it all the time but thanks to udev
consoles would still get their pretty fonts and playful colors.

The En..

..no, wait! You should ask what came of systemd-udev-settle, first.
And why is the service even around if udev is doing all the work?

Udev-settle, like the deceitful snake that he is, laid hidden for years.
He looks innocuous doesn't it? A little hack. Only until it leaves his
den and a poor user[8] drops dead. Obviously, it serves no purpose, as
the service is not part of the boot process anymore, so let's remove it
for good!

About the service, it may not be useful at boot, but it can be started
to pick up changes in vconsole.conf and set the consoles accordingly.
But wait, this doesn't work anymore: the service is never started at
boot (remember f76d2aa6), so switch-to-configuration.pl will not restart
it. Fortunately it can be repaired: here I install a new unit which
does *nothing* on start, but restarts the real service when reloaded.
This perfectly reproduces the original behavior, hopefully without the
original bugs too.

The End?

[1]: https://github.com/NixOS/nixpkgs/commit/cc5421106942ce82473f4afd74d156d8d1e303bd
[2]: https://github.com/systemd/systemd/commit/f6ba8671d83f9fce9a00045d8fa399a1c07ba7fc#diff-84849fddcef81458f69725dc18c6614aade5c4f41a032b6908ebcf1ee6740636
[3]: https://github.com/systemd/systemd/commit/8125e8d38e3aa099c7dce8b0161997b8842aebdc
[4]: https://web.archive.org/web/20180603130107/https://github.com/NixOS/nixpkgs/issues/22470
[5]: https://github.com/NixOS/nixpkgs/issues/81138
[6]: https://web.archive.org/web/20180603130107/https://github.com/NixOS/nixpkgs/issues/22470#issuecomment-330930456
[7]: https://github.com/NixOS/nixpkgs/commit/f76d2aa6e3b4ed6ca9da1e761b1ef2ec36b227c8
[8]: https://github.com/NixOS/nixpkgs/issues/107341
Diffstat (limited to 'nixos/modules/config')
-rw-r--r--nixos/modules/config/console.nix13
1 files changed, 9 insertions, 4 deletions
diff --git a/nixos/modules/config/console.nix b/nixos/modules/config/console.nix
index 1339227f1e0..84ad76246fd 100644
--- a/nixos/modules/config/console.nix
+++ b/nixos/modules/config/console.nix
@@ -144,11 +144,16 @@ in
           ''}
         '';
 
-        systemd.services.systemd-vconsole-setup =
-          {
-            before = optional config.services.xserver.enable "display-manager.service";
-            after = [ "systemd-udev-settle.service" ];
+        systemd.services.reload-systemd-vconsole-setup =
+          { description = "Reset console on configuration changes";
+            wantedBy = [ "multi-user.target" ];
             restartTriggers = [ vconsoleConf consoleEnv ];
+            reloadIfChanged = true;
+            serviceConfig =
+              { RemainAfterExit = true;
+                ExecStart = "${pkgs.coreutils}/bin/true";
+                ExecReload = "/run/current-system/systemd/bin/systemctl restart systemd-vconsole-setup";
+              };
           };
       }