You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.8 KiB

  1. { config, pkgs, lib, ... }:
  2. with lib;
  3. let
  4. python-github-backup = pkgs.python3Packages.buildPythonApplication {
  5. name = "python-github-backup";
  6. src = pkgs.fetchFromGitHub {
  7. owner = "josegonzalez";
  8. repo = "python-github-backup";
  9. rev = "18e78a4d66120961590836e63d1fa939e4d036f3";
  10. sha256 = "1c5qxyv322z5zkx8mxdwdqrnjgqhk00aqcgwkn53b4xkfr2idkbn";
  11. };
  12. patches = [ ./ghbackup-179.patch ];
  13. propagatedBuildInputs = [ pkgs.git ];
  14. };
  15. token = (import /etc/nixos/secret/github_tokens.nix).backup;
  16. makeBackup = pkgs.writeScript "make-ghbackup" ''
  17. #!${pkgs.bash}/bin/bash
  18. set -e
  19. ${python-github-backup}/bin/github-backup m-labs -t ${token} --all -i -o /var/lib/ghbackup/m-labs
  20. ${python-github-backup}/bin/github-backup quartiq -t ${token} --all -i -o /var/lib/ghbackup/quartiq
  21. ${python-github-backup}/bin/github-backup sinara-hw -t ${token} --all -i -o /var/lib/ghbackup/sinara-hw
  22. echo GitHub backup done
  23. '';
  24. cfg = config.services.ghbackup;
  25. in
  26. {
  27. options.services.ghbackup = {
  28. enable = mkOption {
  29. type = types.bool;
  30. default = false;
  31. description = "Enable backups";
  32. };
  33. };
  34. config = mkIf cfg.enable {
  35. systemd.services.ghbackup = {
  36. description = "GitHub backup";
  37. serviceConfig = {
  38. Type = "oneshot";
  39. User = "ghbackup";
  40. Group = "ghbackup";
  41. ExecStart = "${makeBackup}";
  42. };
  43. };
  44. users.users.ghbackup = {
  45. name = "ghbackup";
  46. group = "ghbackup";
  47. description = "GitHub backups user";
  48. isSystemUser = true;
  49. createHome = true;
  50. home = "/var/lib/ghbackup";
  51. useDefaultShell = true;
  52. };
  53. users.extraGroups.ghbackup = {};
  54. systemd.timers.ghbackup = {
  55. description = "GitHub backup";
  56. wantedBy = [ "timers.target" ];
  57. timerConfig.OnCalendar = "daily";
  58. };
  59. };
  60. }