summary refs log tree commit diff
path: root/nixos/modules/system/boot/shutdown.nix
blob: 11041066e07c1406136647223bf11a267a83a8a7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{ config, lib, pkgs, ... }:

with lib;

{

  # This unit saves the value of the system clock to the hardware
  # clock on shutdown.
  systemd.services.save-hwclock =
    { description = "Save Hardware Clock";

      wantedBy = [ "shutdown.target" ];

      unitConfig = {
        DefaultDependencies = false;
        ConditionPathExists = "/dev/rtc";
      };

      serviceConfig = {
        Type = "oneshot";
        ExecStart = "${pkgs.utillinux}/sbin/hwclock --systohc ${if config.time.hardwareClockInLocalTime then "--localtime" else "--utc"}";
      };
    };

  boot.kernel.sysctl."kernel.poweroff_cmd" = "${config.systemd.package}/sbin/poweroff";

}