summary refs log tree commit diff
path: root/nixos/modules/system/boot/shutdown.nix
blob: 8cda7b3aabe8c34e54836db2db08a580725471b2 (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.util-linux}/sbin/hwclock --systohc ${if config.time.hardwareClockInLocalTime then "--localtime" else "--utc"}";
      };
    };

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

}