restic-alarm/flake.nix
Armaël Guéneau cd360b329f flake.nix: add static cross-compiled builds
The nix invocations come from the garage .nix files
2024-08-02 12:55:39 +02:00

94 lines
3.1 KiB
Nix

{
description = "restic-alarm";
inputs = {
cargo2nix = {
url = "github:cargo2nix/cargo2nix/release-0.11.0";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.follows = "cargo2nix/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
};
outputs = { self, nixpkgs, cargo2nix, flake-utils }:
let
compile = import ./compile.nix;
in
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
rec {
packages =
let
packageFor = target: (compile {
inherit system target;
pkgsSrc = nixpkgs;
cargo2nixOverlay = cargo2nix.overlays.default;
release = true;
}).workspace.restic-alarm { compileMode = "build"; };
in
{
# default = native release build
default = packages.restic-alarm;
restic-alarm = packageFor null;
# other = cross-compiled, statically-linked builds
amd64 = packageFor "x86_64-unknown-linux-musl";
i386 = packageFor "i686-unknown-linux-musl";
arm64 = packageFor "aarch64-unknown-linux-musl";
arm = packageFor "armv6l-unknown-linux-musleabihf";
};
}
)
// 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;
};
}