1# Regression test for systemd-timesync having moved the state directory without
2# upstream providing a migration path. https://github.com/systemd/systemd/issues/12131
3
4let
5 common =
6 { lib, ... }:
7 {
8 # override the `false` value from the qemu-vm base profile
9 services.timesyncd.enable = lib.mkForce true;
10 };
11 mkVM = conf: {
12 imports = [
13 conf
14 common
15 ];
16 };
17in
18{
19 name = "systemd-timesyncd";
20 nodes = {
21 current = mkVM { };
22 pre1909 = mkVM (
23 { lib, ... }:
24 {
25 # create the path that should be migrated by our activation script when
26 # upgrading to a newer nixos version
27 system.stateVersion = "19.03";
28 systemd.services.old-timesync-state-dir = {
29 requiredBy = [ "sysinit.target" ];
30 before = [ "systemd-timesyncd.service" ];
31 after = [ "local-fs.target" ];
32 unitConfig.DefaultDependencies = false;
33 serviceConfig.Type = "oneshot";
34 script = ''
35 rm -rf /var/lib/systemd/timesync
36 mkdir -p /var/lib/systemd /var/lib/private/systemd/timesync
37 ln -s /var/lib/private/systemd/timesync /var/lib/systemd/timesync
38 chown systemd-timesync: /var/lib/private/systemd/timesync
39 '';
40 };
41 }
42 );
43 };
44
45 testScript = ''
46 start_all()
47 current.succeed("systemctl status systemd-timesyncd.service")
48 # on a new install with a recent systemd there should not be any
49 # leftovers from the dynamic user mess
50 current.succeed("test -e /var/lib/systemd/timesync")
51 current.succeed("test ! -L /var/lib/systemd/timesync")
52
53 # timesyncd should be running on the upgrading system since we fixed the
54 # file bits in the activation script
55 pre1909.succeed("systemctl status systemd-timesyncd.service")
56
57 # the path should be gone after the migration
58 pre1909.succeed("test ! -e /var/lib/private/systemd/timesync")
59
60 # and the new path should no longer be a symlink
61 pre1909.succeed("test -e /var/lib/systemd/timesync")
62 pre1909.succeed("test ! -L /var/lib/systemd/timesync")
63
64 # after a restart things should still work and not fail in the activation
65 # scripts and cause the boot to fail..
66 pre1909.shutdown()
67 pre1909.start()
68 pre1909.succeed("systemctl status systemd-timesyncd.service")
69 '';
70}