File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 22 pkgs ,
33 lib ,
44 config ,
5+ secrets ,
56 ...
67} :
7-
88{
99 my . system . autoUpgrade = {
1010 enable = true ;
1111 dates = "hourly" ;
1212 flake = "github:LorenzBischof/nixfiles" ;
13+ ntfyTopic = secrets . ntfy-alertmanager ;
1314 } ;
1415
1516 systemd . services = lib . mkIf config . my . system . autoUpgrade . enabled {
Original file line number Diff line number Diff line change 116116 system was powered down.
117117 '' ;
118118 } ;
119+ ntfyUrl = lib . mkOption {
120+ type = lib . types . str ;
121+ default = "https://ntfy.sh" ;
122+ description = "ntfy server URL" ;
123+ } ;
124+ ntfyTopic = lib . mkOption {
125+ type = lib . types . nullOr lib . types . str ;
126+ default = null ;
127+ description = "ntfy topic for notifications" ;
128+ } ;
119129 } ;
120130 config = lib . mkIf ( cfg . enabled ) {
121131 environment . etc . git-revision . text = inputs . self . rev ;
159169 } ;
160170 # Prefer not to autoupgrade when on battery
161171 unitConfig . ConditionACPower = true ;
172+
173+ onSuccess = lib . mkIf ( cfg . ntfyTopic != null ) [ "ntfy-upgrade-success.service" ] ;
174+ onFailure = lib . mkIf ( cfg . ntfyTopic != null ) [ "ntfy-upgrade-failure.service" ] ;
162175 } ;
163176
177+ systemd . services . "ntfy-upgrade-success" = lib . mkIf ( cfg . ntfyTopic != null ) {
178+ script = ''
179+ if [ "$(systemctl show nixos-upgrade -p ConditionResult --value)" = "no" ]; then
180+ exit 0
181+ fi
182+ ${ pkgs . curl } /bin/curl -s \
183+ -H "Title: NixOS Upgrade Succeeded on $(${ pkgs . nettools } /bin/hostname)" \
184+ -H "Tags: white_check_mark" \
185+ -d "System updated successfully to ${ inputs . self . rev or "unknown" } " \
186+ "${ cfg . ntfyUrl } /${ cfg . ntfyTopic } "
187+ '' ;
188+ } ;
189+
190+ systemd . services . "ntfy-upgrade-failure" = lib . mkIf ( cfg . ntfyTopic != null ) {
191+ script = ''
192+ ${ pkgs . curl } /bin/curl -s \
193+ -H "Title: NixOS Upgrade Failed on $(${ pkgs . nettools } /bin/hostname)" \
194+ -H "Tags: warning" \
195+ -H "Priority: high" \
196+ -d "System upgrade failed!" \
197+ "${ cfg . ntfyUrl } /${ cfg . ntfyTopic } "
198+ '' ;
199+ } ;
164200 } ;
165201}
You can’t perform that action at this time.
0 commit comments