Auto-updates are enabled on my system, but they’re so very unpredictable. Just now had one running, I was thinking “why is my PC lagging” until you hear a symphony of USB connect/disconnect sounds and you realise, “ohh, it was auto-update”.
So the question is, is there some kind of way to receive a notification when auto-update is running? Preferably with progressbar. Or maybe a way to get notifications when there are updates available? Thanks!
- Can notifications be started from a systemd unit? Kind of. - notify-sendcan be invoked from systemd, but getting the correct user notified is non-trivial and I’m not sure how it would be done on NixOS.- Can - nixos-rebuildhave a progress bar? Not really. It’s not a process with a predictable end time.- Can there be notifications when updates are available? There are scripts out there (like this one which I have never used) which can poll git repositories and run - notify-send, but that’s not very useful. Instead, it’s worth knowing that most of the cost of auto-upgrade is running the- nixos-rebuildcommand at all, even if there are no available upgrades!- Instead, consider setting - system.autoUpgrade.datesto a fixed time when you definitely won’t use the computer, and also set- system.autoUpgrade.persistent. This will run auto-upgrade on boot in the worst case.- Also, USB devices should not be disconnecting on every update. If USB disconnections happen under high load, check - dmesgfor possible hints; you may merely need to add an override to- boot.kernelParams.- Autoupdates during times when I’m not using the system might not work, as I usually shut down the PC when it’s not in use… 😅 Looks like the best way to deal with the issue is to try and write an application myself of sorts? - Would love to have a diff before building a new version, but reading this blogpost it seems you can only get one afterwards https://blog.tjll.net/previewing-nixos-system-updates/ - Anyways, if I were to make an app myself, although not very reliable, using the - [] built,logging during the- nixos-rebuildcommand could be a way to get some progressbar I think?
 
- I think you can do something like this in your config (not tested): - systemd.services.nixos-upgrade = { path = [ pkgs.systemd ]; serviceConfig.ExecStartPre = pkgs.writeShellScript "nixos-upgrade-notify-start" ''systemd-run --machine <YOUR_USER_NAME>@.host --user ${pkgs.libnotify}/bin/notify-send --urgency critical "System upgrade starting now!"''; serviceConfig.ExecStartPost = pkgs.writeShellScript "nixos-upgrade-notify-end" ''systemd-run --machine <YOUR_USER_NAME>@.host --user ${pkgs.libnotify}/bin/notify-send "System upgrade done!"''; };- Obviously, replace - <YOUR_USER_NAME>with the user you’d like to receive notifications.- This will send you a notification every time this service starts and finishes. 


