citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

git.nix (1332B)


      1 extra:
      2 { config, lib, pkgs, ... }:
      3 let pubkey = pkgs.fetchurl {
      4                url = "https://jb55.com/pgp.txt";
      5                sha256 = "012910961fb58b886fc44a8ebedba394240be4e17604703f3b094eef86d5aca5";
      6              };
      7 in
      8 {
      9   systemd.services.gitzero-backup = {
     10     description = "Git repo backups";
     11 
     12     environment = {
     13       AWS_ACCESS_KEY_ID = extra.private.aws_access_key;
     14       AWS_SECRET_ACCESS_KEY = extra.private.aws_secret_key;
     15     };
     16 
     17     unitConfig.OnFailure = "notify-failed@%n.service";
     18     # Saturday morning? should be fine
     19     startAt = "*-*-* 03:57:00";
     20     serviceConfig.ExecStart = let script = pkgs.writeScript "gitzero-backup" ''
     21       #!${pkgs.bash}/bin/bash
     22       set -euo pipefail
     23 
     24       filename="Monstercat-gitzero-$(date +%F-%H%M%z).tar.xz.gpg"
     25 
     26       ${pkgs.gnupg}/bin/gpg2 --import ${pubkey} || echo "already have key!"
     27 
     28       ${pkgs.gnutar}/bin/tar --exclude=/var/git/db-backup -cf - /var/git  \
     29          | ${pkgs.pxz}/bin/pxz -T24 \
     30          | ${pkgs.gnupg}/bin/gpg2 \
     31               -e \
     32               --compress-level 0 \
     33               --yes \
     34               --no-tty \
     35               --output - \
     36               -r 0x6D3E2004415AF4A3 \
     37          | ${pkgs.awscli}/bin/aws s3 \
     38               cp - \
     39               "s3://data.monstercat.com/backups/gitzero/$filename"
     40 
     41     '';
     42     in "${script}";
     43   };
     44 
     45 }