diff --git a/flakes/common/nix_modules/timezone_auto.nix b/flakes/common/nix_modules/timezone_auto.nix index 4b322d9d..3d2ee7f7 100644 --- a/flakes/common/nix_modules/timezone_auto.nix +++ b/flakes/common/nix_modules/timezone_auto.nix @@ -20,4 +20,45 @@ after = [ "dbus.socket" ]; wants = [ "dbus.socket" ]; }; + + systemd.services.fix-localtime-symlink = { + description = "Fix /etc/localtime symlink to be absolute"; + wantedBy = [ "multi-user.target" ]; + after = [ "automatic-timezoned.service" ]; + wants = [ "automatic-timezoned.service" ]; + + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + ExecStart = pkgs.writeShellScript "fix-localtime-symlink" '' + target=$(${pkgs.coreutils}/bin/readlink /etc/localtime 2>/dev/null || true) + if [ -z "$target" ]; then + exit 0 + fi + + if [[ "$target" == /* ]]; then + exit 0 + fi + + abs_target="/etc/$target" + if [ -e "$abs_target" ]; then + ${pkgs.coreutils}/bin/ln -sf "$abs_target" /etc/localtime + fi + ''; + }; + + unitConfig = { + ConditionPathIsSymbolicLink = "/etc/localtime"; + }; + }; + + systemd.paths.fix-localtime-symlink = { + description = "Watch /etc/localtime for changes"; + wantedBy = [ "multi-user.target" ]; + + pathConfig = { + PathChanged = "/etc/localtime"; + Unit = "fix-localtime-symlink.service"; + }; + }; }