Added timer to check if /etc/nixos is clean

This commit is contained in:
Samy Avrillon 2025-09-20 22:52:31 +02:00
parent 3343ec1dec
commit f50bb2e8c3

View File

@ -5,14 +5,17 @@
...
}:
let
list-replace = l: e: e':
(let i = lib.lists.findFirstIndex (a: a == e) (-1) l; in
if (i == (-1)) then builtins.throw "Could not find item in list" else (lib.lists.take i l ++ [e'] ++ lib.lists.drop (i+1) l));
dovecot-mysaa = pkgs.dovecot.overrideAttrs {
configureFlags =
list-replace (list-replace pkgs.dovecot.configureFlags "--sysconfdir=/etc" "--sysconfdir=/home/mysaa/.local/etc/")
"--localstatedir=/var" "--localstatedir=/home/mysaa/.local/var";
}; in
clean-nixos-git-check-script = pkgs.writeScript "clean-nixos-git-check" ''
if [ -z "$(${pkgs.git}/bin/git -C /etc/nixos status -u --porcelain)" ]
then
echo "/etc/nixos is clean !"
exit 0
else
${pkgs.zenity}/bin/zenity --info --text="/etc/nixos/ is not clean, don't forget to commit !"
exit 0
fi
'';
in
{
environment.systemPackages = with pkgs; [
@ -87,4 +90,33 @@
WantedBy = [ "timers.target" ];
};
};
home-manager.users.mysaa.systemd.user = {
services.check-nixos-git-clean = {
Unit = {
Description = "Sends a notification if /etc/nixos is not clean";
};
Service = {
Type = "oneshot";
ExecStart = "${pkgs.bash}/bin/bash ${clean-nixos-git-check-script}";
};
};
timers.check-nixos-git-clean = {
Unit = {
Description = "Bi-hourly reminder that /etc/nixos should be clean";
};
Timer = {
OnBootSec = "5min";
OnUnitActiveSec = "30min";
Persistent = "true";
Unit = "check-nixos-git-clean.service";
};
Install = {
WantedBy = [ "timers.target" ];
};
};
};
}