diff --git a/loki/configuration.nix b/loki/configuration.nix index 8618abc..8f8e8a1 100644 --- a/loki/configuration.nix +++ b/loki/configuration.nix @@ -7,6 +7,7 @@ /etc/nixos/hardware-configuration.nix /home/don/nixos/workstation/configuration.nix /home/don/nixos/workstation/sway.nix + /home/don/nixos/workstation/detect-reboot-needed.nix ]; networking.hostName = "loki"; } diff --git a/workstation/detect-reboot-needed.nix b/workstation/detect-reboot-needed.nix new file mode 100644 index 0000000..5f41ae0 --- /dev/null +++ b/workstation/detect-reboot-needed.nix @@ -0,0 +1,30 @@ +{ pkgs, ... }: + +let + readlink = "${pkgs.coreutils}/bin/readlink"; + notify-send = "${pkgs.libnotify}/bin/notify-send"; +in { + systemd.user.services.detect-reboot-for-upgrade = { + script = '' + set -eu -o pipefail + booted="$(${readlink} /run/booted-system/{initrd,kernel,kernel-modules})" + built="$(${readlink} /nix/var/nix/profiles/system/{initrd,kernel,kernel-modules})" + if [[ "''${booted}" != "''${built}" ]]; + then + echo "Looks like we need a reboot!" + ${notify-send} --urgency=low --icon=system-reboot "Reboot is needed for a NixOS upgrade." + fi + ''; + serviceConfig = { + Type = "oneshot"; + }; + }; + systemd.user.timers.detect-reboot-for-upgrade = { + wantedBy = [ "timers.target" ]; + partOf = [ "detect-reboot-for-upgrade.service" ]; + timerConfig = { + OnCalendar = "hourly"; + Unit = "detect-reboot-for-upgrade.service"; + }; + }; +}