From a0d464033c2bacffa9c05d27903fb03cd09ace46 Mon Sep 17 00:00:00 2001 From: Linus Heckemann Date: Mon, 31 Jul 2017 15:55:24 +0100 Subject: nixos/timezone: support imperative timezone configuration (#26608) Fixes #26469. --- nixos/tests/timezone.nix | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 nixos/tests/timezone.nix (limited to 'nixos/tests') diff --git a/nixos/tests/timezone.nix b/nixos/tests/timezone.nix new file mode 100644 index 00000000000..2204649a3fc --- /dev/null +++ b/nixos/tests/timezone.nix @@ -0,0 +1,45 @@ +{ + timezone-static = import ./make-test.nix ({ pkgs, ... }: { + name = "timezone-static"; + meta.maintainers = with pkgs.lib.maintainers; [ lheckemann ]; + + machine.time.timeZone = "Europe/Amsterdam"; + + testScript = '' + $machine->waitForUnit("dbus.socket"); + $machine->fail("timedatectl set-timezone Asia/Tokyo"); + my @dateResult = $machine->execute('date -d @0 "+%Y-%m-%d %H:%M:%S"'); + $dateResult[1] eq "1970-01-01 01:00:00\n" or die "Timezone seems to be wrong"; + ''; + }); + + timezone-imperative = import ./make-test.nix ({ pkgs, ... }: { + name = "timezone-imperative"; + meta.maintainers = with pkgs.lib.maintainers; [ lheckemann ]; + + machine.time.timeZone = null; + + testScript = '' + $machine->waitForUnit("dbus.socket"); + + # Should default to UTC + my @dateResult = $machine->execute('date -d @0 "+%Y-%m-%d %H:%M:%S"'); + print $dateResult[1]; + $dateResult[1] eq "1970-01-01 00:00:00\n" or die "Timezone seems to be wrong"; + + $machine->succeed("timedatectl set-timezone Asia/Tokyo"); + + # Adjustment should be taken into account + my @dateResult = $machine->execute('date -d @0 "+%Y-%m-%d %H:%M:%S"'); + print $dateResult[1]; + $dateResult[1] eq "1970-01-01 09:00:00\n" or die "Timezone was not adjusted"; + + # Adjustment should persist across a reboot + $machine->shutdown; + $machine->waitForUnit("dbus.socket"); + my @dateResult = $machine->execute('date -d @0 "+%Y-%m-%d %H:%M:%S"'); + print $dateResult[1]; + $dateResult[1] eq "1970-01-01 09:00:00\n" or die "Timezone adjustment was not persisted"; + ''; + }); +} -- cgit 1.4.1