Home: Add repo-mirror service.

This commit is contained in:
Dmitry Voronin 2025-01-22 12:43:14 +03:00
parent 947f01982d
commit 4e94fc40ec
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k
2 changed files with 54 additions and 2 deletions

View file

@ -6,7 +6,7 @@
}@args:
let
bash = import <home/program/bash> args;
script = pkgs.writeText "backupScript" ''
script = pkgs.writeText "backup-script" ''
source ${bash.modulesFile}
function report() {
@ -81,7 +81,7 @@ in
{
systemd.services.backup = util.mkStaticSystemdService {
enable = true;
description = "Home system backup.";
description = "Home system backup";
serviceConfig.Type = "oneshot";
path = with pkgs; [
bashInteractive

View file

@ -0,0 +1,52 @@
{
__findFile,
config,
pkgs,
secret,
util,
...
}@args:
{
programs.git = {
enable = true;
config = {
gpg.ssh.allowedSignersFile = toString secret.crypto.sign.git.allowed;
};
};
systemd.services.repo-mirror = util.mkStaticSystemdService {
enable = true;
description = "NixOS repo mirror push service";
serviceConfig.Type = "oneshot";
environment.GIT_SSH_COMMAND = "ssh -o UserKnownHostsFile=/root/.ssh/known_hosts";
path = with pkgs; [
bash
coreutils
git
openssh
];
script = ''
pushd /tmp
rm -rf ./nixos-mirror
git clone --single-branch --branch=main ${config.module.const.url} ./nixos-mirror
pushd ./nixos-mirror
git verify-commit HEAD && git fsck || {
echo "Verification failed."
exit 1
};
git remote add github git@github.com:voronind-com/nix.git
git remote add codeberg git@codeberg.org:voronind/nix.git
timeout 10m git push --force github main
timeout 10m git push --force codeberg main
'';
};
systemd.timers.repo-mirror = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "*-*-* 05:55:00";
Persistent = true;
Unit = "repo-mirror.service";
};
};
}