Self-host your own digital island
1# nixos-mailserver: a simple mail server 2# Copyright (C) 2016-2018 Robin Raymond 3# 4# This program is free software: you can redistribute it and/or modify 5# it under the terms of the GNU General Public License as published by 6# the Free Software Foundation, either version 3 of the License, or 7# (at your option) any later version. 8# 9# This program is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program. If not, see <http://www.gnu.org/licenses/> 16 17{ config, pkgs, lib, ... }: 18 19with lib; 20 21let 22 cfg = config.mailserver; 23in 24{ 25 config = mkIf (cfg.enable && cfg.rebootAfterKernelUpgrade.enable) { 26 systemd.services.nixos-upgrade.serviceConfig.ExecStartPost = pkgs.writeScript "post-upgrade-check" '' 27 #!${pkgs.stdenv.shell} 28 29 # Checks whether the "current" kernel is different from the booted kernel 30 # and then triggers a reboot so that the "current" kernel will be the booted one. 31 # This is just an educated guess. If the links do not differ the kernels might still be different, according to spacefrogg in #nixos. 32 33 current=$(readlink -f /run/current-system/kernel) 34 booted=$(readlink -f /run/booted-system/kernel) 35 36 if [ "$current" == "$booted" ]; then 37 echo "kernel version seems unchanged, skipping reboot" | systemd-cat --priority 4 --identifier "post-upgrade-check"; 38 else 39 echo "kernel path changed, possibly a new version" | systemd-cat --priority 2 --identifier "post-upgrade-check" 40 echo "$booted" | systemd-cat --priority 2 --identifier "post-upgrade-kernel-check" 41 echo "$current" | systemd-cat --priority 2 --identifier "post-upgrade-kernel-check" 42 ${cfg.rebootAfterKernelUpgrade.method} 43 fi 44 ''; 45 }; 46}