Files
nixos/common/modules/home/services.nix

42 lines
1.1 KiB
Nix
Raw Permalink Normal View History

2026-03-27 19:32:51 +01:00
{pkgs, ...}: let
devShellsDir = "$HOME/.config/nix-shells";
nixConfigDir = "/etc/nixos";
syncScript = pkgs.writeShellScript "sync-all-repos" ''
repos=("${devShellsDir}" "${nixConfigDir}")
for repo in "''${repos[@]}"; do
echo "Syncing $repo..."
if ! ${pkgs.git}/bin/git -C "$repo" pull --rebase --autostash; then
${pkgs.libnotify}/bin/notify-send -u critical "Sync Failed" "Conflict or network error in $repo"
else
${pkgs.git}/bin/git -C "$repo" add -N . 2>/dev/null || true
fi
done
'';
in {
systemd.user.services.sync-nix-repos = {
Unit = {
2026-03-27 19:32:51 +01:00
Description = "Background sync for Nix Config and Dev Shells";
After = ["network-online.target"];
Wants = ["network-online.target"];
};
Service = {
Type = "oneshot";
2026-03-27 19:32:51 +01:00
ExecStart = "${syncScript}";
PassEnvironment = ["DBUS_SESSION_BUS_ADDRESS" "DISPLAY"];
};
};
2026-03-27 19:32:51 +01:00
systemd.user.timers.sync-nix-repos = {
Unit.Description = "Hourly sync for all Nix repositories";
Timer = {
OnBootSec = "2m";
OnUnitActiveSec = "1h";
Persistent = true;
};
2026-03-27 19:32:51 +01:00
Install.WantedBy = ["timers.target"];
};
}