2024-04-08 15:27:50 +00:00
|
|
|
{
|
|
|
|
description = "restic-alarm";
|
2024-04-10 13:07:29 +00:00
|
|
|
inputs = {
|
2024-04-10 13:28:44 +00:00
|
|
|
cargo2nix = {
|
|
|
|
url = "github:cargo2nix/cargo2nix/release-0.11.0";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2024-04-10 13:07:29 +00:00
|
|
|
flake-utils.follows = "cargo2nix/flake-utils";
|
2024-04-10 13:28:44 +00:00
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
|
2024-04-10 13:07:29 +00:00
|
|
|
};
|
|
|
|
|
2024-04-11 11:41:29 +00:00
|
|
|
outputs = { self, nixpkgs, cargo2nix, flake-utils }:
|
2024-04-10 13:07:29 +00:00
|
|
|
flake-utils.lib.eachDefaultSystem (system:
|
|
|
|
let
|
|
|
|
pkgs = import nixpkgs {
|
|
|
|
inherit system;
|
|
|
|
overlays = [cargo2nix.overlays.default];
|
|
|
|
};
|
|
|
|
|
|
|
|
rustPkgs = pkgs.rustBuilder.makePackageSet {
|
|
|
|
rustVersion = "1.75.0";
|
|
|
|
packageFun = import ./Cargo.nix;
|
|
|
|
};
|
|
|
|
|
|
|
|
in rec {
|
|
|
|
packages = {
|
|
|
|
restic-alarm = (rustPkgs.workspace.restic-alarm {});
|
|
|
|
default = packages.restic-alarm;
|
|
|
|
};
|
|
|
|
}
|
2024-04-11 11:41:29 +00:00
|
|
|
) // rec {
|
|
|
|
nixosModules.restic-alarm = { config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.custom.restic-alarm;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.custom.restic-alarm = {
|
|
|
|
enable = mkEnableOption (lib.mdDoc "restic-alarm: send alarms for inactive backups");
|
|
|
|
|
|
|
|
env_file = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
description = lib.mdDoc
|
|
|
|
"The file containing the environment variables to pass to restic-alarm, for e.g. S3 access keys";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.restic-alarm =
|
|
|
|
let
|
|
|
|
pkg = self.packages.${pkgs.system}.default;
|
|
|
|
in {
|
|
|
|
description = "restic-alarm: send alarms for inactive backups";
|
|
|
|
after = [ "network.target" "network-online.target" ];
|
|
|
|
wants = [ "network.target" "network-online.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
restartTriggers = [ cfg.env_file ];
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkg}/bin/restic-alarm";
|
|
|
|
DynamicUser = true;
|
|
|
|
EnvironmentFile = "${cfg.env_file}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.timers.restic-alarm = {
|
|
|
|
partOf = [ "restic-alarm.service" ];
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
timerConfig = {
|
|
|
|
Unit = "restic-alarm.service";
|
|
|
|
Persistent = true;
|
|
|
|
# every 6 hours
|
|
|
|
OnCalendar = "*-*-* 00/6:00:00";
|
|
|
|
RandomizedDelaySec = "1h";
|
|
|
|
FixedRandomDelay = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
nixosModules.default = nixosModules.restic-alarm;
|
|
|
|
};
|
2024-04-08 15:27:50 +00:00
|
|
|
}
|