Created
January 6, 2023 15:39
-
-
Save mfenniak/dd551fa7409823ba5425103ef1396a51 to your computer and use it in GitHub Desktop.
NixOS module that provides hourly notifications when a reboot is needed for a kernel, initrd, or kernel-module upgrade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ 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"; | |
}; | |
}; | |
} |
Hey @duckunix -- what I would recommend is to put it into a separate file next to your configuration.nix file, and then add it to imports
in your main configuration.nix. For example, here's a snippet of my configuration.nix...
{
...
imports = [
./smb-mounts.nix
./libvirtd.nix
./detect-reboot-needed.nix
];
...
}
It's a little easier this way to keep your main configuration.nix file nicely organized.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So, for the new NixOS person, how would I use this? Just including it in my configuration.nix file?