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

50 lines
1.5 KiB
Nix
Raw Normal View History

2023-12-29 16:43:40 +01:00
{ config, lib, pkgs, ... }:
2023-12-30 23:39:33 +01: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-30 23:39:33 +01:00
${
lib.getExe pkgs.git
} clone git@codeberg.org:jopejoe1/nix-conf.git /var/lib/repo-sync
${
lib.getExe pkgs.git
} -C /var/lib/repo-sync remote add github git@github.com:jopejoe1/nix-conf.git
${
lib.getExe pkgs.git
} -C /var/lib/repo-sync remote add gitlab git@gitlab.com:jopejoe1/nix-conf.git
2023-12-29 16:43:40 +01:00
${lib.getExe pkgs.git} -C /var/lib/repo-sync pull -r github main
${lib.getExe pkgs.git} -C /var/lib/repo-sync pull -r gitlab main
${lib.getExe pkgs.nix} flake update /var/lib/repo-sync
2023-12-30 23:39:33 +01:00
${
lib.getExe pkgs.git
} -C /var/lib/repo-sync commit -m "flack.lock updated on `$(${pkgs.coreutils}/bin/date)`"
2023-12-29 16:43:40 +01:00
${lib.getExe pkgs.git} -C /var/lib/repo-sync push origin
${lib.getExe pkgs.git} -C /var/lib/repo-sync push github
${lib.getExe pkgs.git} -C /var/lib/repo-sync push gitlab
${pkgs.coreutils}/bin/rm -r /var/lib/repo-sync
'';
path = [ pkgs.openssh ];
serviceConfig = {
Type = "oneshot";
User = "root";
};
};
};
}