nixos/modules/services/restic-server/default.nix

83 lines
2.1 KiB
Nix
Raw Normal View History

2023-06-06 22:30:02 +02:00
{ config, inputs, lib, pkgs, ... }:
2022-01-27 19:32:05 +01:00
let
2023-06-06 22:30:02 +02:00
cfg = config.services.az-restic-server;
2022-01-27 19:32:05 +01:00
in
{
2023-06-06 22:30:02 +02:00
options = {
services.az-restic-server = {
enable = lib.mkEnableOption "Enable a restic server.";
repository = lib.mkOption {
type = lib.types.path;
description = "The directory where your backups get stored.";
default = "/var/lib/restic-server";
};
};
};
2022-11-04 16:49:46 +01:00
2023-06-06 22:30:02 +02:00
config = lib.mkIf cfg.enable {
services.az-telegram-notifications.enable = true;
2023-06-06 22:30:02 +02:00
age.secrets.resticKey = {
file = "${inputs.self}/scrts/restic.key.age";
mode = "440";
owner = "restic";
group = "restic";
};
environment.systemPackages = with pkgs; [
restic
];
2022-02-28 15:10:58 +01:00
2023-06-06 22:30:02 +02:00
fileSystems."${cfg.repository}" = {
device = "10.7.89.108:restic-server";
fsType = "nfs";
options = [ "noatime" "hard" "nfsvers=4.0" ];
2022-02-28 17:33:18 +01:00
};
2023-06-06 22:30:02 +02:00
services.restic.server = {
enable = true;
dataDir = cfg.repository;
extraFlags = [ "--no-auth" ];
};
networking.firewall.allowedTCPPorts = [ 8000 ];
2022-02-28 15:10:58 +01:00
2023-06-06 22:30:02 +02:00
systemd.services.restic-prune = {
serviceConfig = {
Type = "oneshot";
User = "restic";
};
onFailure = [ "unit-status-telegram@%n.service" ];
script = ''
${pkgs.restic}/bin/restic \
--repo ${cfg.repository} \
--password-file ${config.age.secrets.resticKey.path} \
prune \
'';
};
2022-11-21 08:36:21 +01:00
2023-06-06 22:30:02 +02:00
systemd.timers.restic-prune = {
wantedBy = [ "timers.target" ];
partOf = [ "restic-prune.service" ];
timerConfig.OnCalendar = [ "*-*-* 08:00:00" ];
};
systemd.services.restic-check = {
serviceConfig = {
Type = "oneshot";
User = "restic";
};
onFailure = [ "unit-status-telegram@%n.service" ];
script = ''
${pkgs.restic}/bin/restic \
--repo ${cfg.repository} \
--password-file ${config.age.secrets.resticKey.path} \
check \
'';
};
systemd.timers.restic-check = {
wantedBy = [ "timers.target" ];
partOf = [ "restic-check.service" ];
timerConfig.OnCalendar = [ "*-*-* 07:00:00" ];
2022-11-21 08:36:21 +01:00
};
2022-02-28 15:10:58 +01:00
};
2022-01-27 19:32:05 +01:00
}