git-sync: Replace with git-sync

This commit is contained in:
Geoffrey Frogeye 2024-01-11 22:25:52 +01:00
parent f83806a307
commit 033f411060
Signed by: geoffrey
GPG key ID: C72403E7F82E6AD8

View file

@ -3,17 +3,23 @@
config = lib.mkIf config.programs.git.enable { config = lib.mkIf config.programs.git.enable {
home.packages = [ home.packages = [
(pkgs.writeShellApplication { (pkgs.writeShellApplication {
name = "git-sync-init"; name = "git-sync";
text = (lib.strings.concatLines text = (lib.strings.concatLines
(map (r: ''[ -d "${r.path}" ] || ${pkgs.git}/bin/git clone "${r.uri}" "${r.path}"'') (map
(lib.attrsets.attrValues config.services.git-sync.repositories) (r: ''
) echo "===== ${r.path}"
); if [ ! -d "${r.path}" ]
}) then
(pkgs.writeShellApplication { ${pkgs.git}/bin/git clone "${r.uri}" "${r.path}"
name = "git-sync-pull"; else
text = (lib.strings.concatLines (
(map (r: ''(cd "${r.path}"; echo "$PWD"; ${pkgs.git}/bin/git pull || true)'') cd "${r.path}"
${pkgs.git}/bin/git diff --quiet || echo "Repository is dirty!"
${pkgs.git}/bin/git pull || true
${pkgs.git}/bin/git push || true
)
fi
'')
(lib.attrsets.attrValues config.services.git-sync.repositories) (lib.attrsets.attrValues config.services.git-sync.repositories)
) )
); );