nix-conf/nixos-modules/repo-sync/default.nix

53 lines
1.3 KiB
Nix
Raw Normal View History

2024-07-10 23:02:54 +02:00
{
config,
lib,
pkgs,
...
}:
2023-12-29 16:43:40 +01:00
2024-07-10 23:02:54 +02:00
let
cfg = config.jopejoe1.repo-sync;
in
{
2023-12-29 16:43:40 +01:00
options.jopejoe1.repo-sync = {
enable = lib.mkEnableOption "Enable Repo Sync";
};
config = lib.mkIf cfg.enable {
systemd.timers."repo-sync" = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = "5m";
OnUnitActiveSec = "15m";
Unit = "repo-sync.service";
};
};
systemd.services."repo-sync" = {
script = ''
2023-12-31 14:52:49 +01:00
git clone git@codeberg.org:jopejoe1/nix-conf.git /var/lib/repo-sync
git -C /var/lib/repo-sync remote add github git@github.com:jopejoe1/nix-conf.git
git -C /var/lib/repo-sync remote add gitlab git@gitlab.com:jopejoe1/nix-conf.git
git -C /var/lib/repo-sync pull -r github main
git -C /var/lib/repo-sync pull -r gitlab main
nix flake update /var/lib/repo-sync
git -C /var/lib/repo-sync commit -m "flack.lock updated on `$(date)`"
git -C /var/lib/repo-sync push origin
git -C /var/lib/repo-sync push github
git -C /var/lib/repo-sync push gitlab
rm -r /var/lib/repo-sync
2023-12-29 16:43:40 +01:00
'';
2024-07-10 23:02:54 +02:00
path = [
pkgs.openssh
pkgs.git
pkgs.coreutils
pkgs.nix
];
2023-12-29 16:43:40 +01:00
serviceConfig = {
Type = "oneshot";
User = "root";
};
};
};
}