nixbld: add simple backups (WIP)

This commit is contained in:
Sebastien Bourdeauducq 2019-05-24 15:19:33 +08:00
parent 64eaa90250
commit 42fac07c85
2 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,40 @@
{ config, pkgs, lib, ... }:
with lib;
let
makeBackup = pkgs.writeScript "make-backup" ''
#!${pkgs.bash}/bin/bash
${pkgs.gnutar}/bin/tar cf - /etc/nixos | \
${pkgs.bzip2}/bin/bzip2 | \
${pkgs.gnupg}/bin/gpg --symmetric --batch --passphrase-file /etc/nixos/secret/backup-passphrase | \
${pkgs.rclone}/bin/rclone rcat --config /etc/nixos/secret/rclone.conf dropbox:backup-`date +%F`.tar.bz2.gpg
echo Backup done
'';
cfg = config.services.homu;
in
{
options.services.mlabs-backup = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable backups";
};
};
config = mkIf cfg.enable {
systemd.services.mlabs-backup = {
description = "M-Labs backup";
serviceConfig = {
Type = "oneshot";
User = "root";
Group = "root";
ExecStart = "${makeBackup}";
};
};
systemd.timers.mlabs-backup = {
description = "M-Labs backup";
wantedBy = [ "timers.target" ];
timerConfig.OnCalendar = "weekly";
};
};
}

View File

@ -12,6 +12,7 @@ in
[ # Include the results of the hardware scan. [ # Include the results of the hardware scan.
./hardware-configuration.nix ./hardware-configuration.nix
./homu/nixos-module.nix ./homu/nixos-module.nix
./backup-module.nix
]; ];
# Use the systemd-boot EFI boot loader. # Use the systemd-boot EFI boot loader.
@ -178,6 +179,7 @@ ACTION=="add", SUBSYSTEM=="tty", \
address localhost address localhost
''; '';
}; };
services.mlabs-backup.enable = true;
services.gitea = { services.gitea = {
enable = true; enable = true;