Skip to content

Commit

Permalink
Abstract out utils.simple-timer and use it.
Browse files Browse the repository at this point in the history
  • Loading branch information
edanaher committed Oct 24, 2017
1 parent 5762cf1 commit 5887967
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 50 deletions.
31 changes: 6 additions & 25 deletions chileh-backups.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{ config, lib, pkgs, ... }:

let two-days = 60 * 60 * 24 * 2 - 60; in
let two-days = 60 * 60 * 24 * 2 - 60;
utils = import ./utils.nix;
in
{
config = lib.mkIf config.host.chileh-backups.enable {
services.periodimail.intervals = [ two-days ];
Expand All @@ -20,14 +22,7 @@ let two-days = 60 * 60 * 24 * 2 - 60; in
};
};

systemd.timers.backup-deretheni = {
description = "Backup deretheni daily";
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "daily";
Persistent = true;
};
};
systemd.timers.backup-deretheni = utils.simple-timer "daily" "Backup deretheni daily";

systemd.services.snapshot-chileh-edanaher = {
description = "Snapshot chileh homedir";
Expand All @@ -39,14 +34,7 @@ let two-days = 60 * 60 * 24 * 2 - 60; in
};
};

systemd.timers.snapshot-chileh-edanaher = {
description = "Snapshot chileh homedir hourly";
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "hourly";
Persistent = true;
};
};
systemd.timers.snapshot-chileh-edanaher = utils.simple-timer "hourly" "Snapshot chileh homedir hourly";

systemd.services.snapshot-chileh-edanaher-to-borg = {
description = "Copy chileh homedir snapshots to borg";
Expand All @@ -57,14 +45,7 @@ let two-days = 60 * 60 * 24 * 2 - 60; in
};
};

systemd.timers.snapshot-chileh-edanaher-to-borg = {
description = "Copy chileh homedir snapshots to borg daily";
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "daily";
Persistent = true;
};
};
systemd.timers.snapshot-chileh-edanaher-to-borg = utils.simple-timer "daily" "Copy chileh homedir snapshots to borg daily";
};

options = {
Expand Down
9 changes: 1 addition & 8 deletions host/hosts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,7 @@ let
};
};

systemd.timers.check-edanaher-mail = {
description = "Check mail for edanaher every half hour";
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "*-*-* *:00,30:00";
Persistent = true;
};
};
systemd.timers.check-edanaher-mail = utils.simple-timer "*-*-* *:00,30:00" "Check mail for edanaher every half hour";

host.monitor-disks = {
"/" = 90;
Expand Down
3 changes: 2 additions & 1 deletion host/utils.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ lib }:

{
let parent = import ../utils.nix; in
parent // {
select = v: set: let all = lib.mapAttrs (name: data: lib.mkIf (name == v) data) set;
in lib.mkMerge (builtins.attrValues all);
}
10 changes: 2 additions & 8 deletions services/angell-classes.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let angell-path = "/var/run/angell-classes";
${update-script} > ${angell-path}/index.html.tmp
mv ${angell-path}/index.html.tmp ${angell-path}/index.html
'';
utils = import ../utils.nix;
in
{
config = lib.mkIf config.host.angell-classes.enable {
Expand All @@ -33,14 +34,7 @@ in
};
};

systemd.timers.update-angell-classes= {
description = "Scrape updates for Angell classes daily";
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "daily";
Persistent = true;
};
};
systemd.timers.update-angell-classes = utils.simple-timer "daily" "Scrape updates for Angell classes daily";
};
options = {
host.angell-classes.enable = lib.mkOption {
Expand Down
10 changes: 2 additions & 8 deletions services/disk-mon.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{config, lib, pkgs, ...}:

let
utils = import ../utils.nix;
escapeSlash = builtins.replaceStrings [ "/" ] [ "_" ];
mon-script-template = builtins.readFile ./disk-mon.sh;
mon-script-text = disk: usage: builtins.replaceStrings [ "$DISK" "$USAGE" ] [ disk usage ] mon-script-template;
Expand All @@ -17,14 +18,7 @@ let
};
};

mon-timer-for = disk: usage: {
description = "Monitor usage for ${disk} at ${toString usage} daily";
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "daily";
Persistent = true;
};
};
mon-timer-for = disk: usage: utils.simple-timer "daily" "Monitor usage for ${disk} at ${toString usage} daily";

services = lib.mapAttrs' (disk: usage: lib.nameValuePair ("monitor-disk-" + escapeSlash disk) (mon-service-for disk usage)) config.host.monitor-disks;
timers = lib.mapAttrs' (disk: usage: lib.nameValuePair ("monitor-disk-" + escapeSlash disk) (mon-timer-for disk usage)) config.host.monitor-disks;
Expand Down
10 changes: 10 additions & 0 deletions utils.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
simple-timer = interval: description: {
description = description;
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = interval;
Persistent = true;
};
};
}

0 comments on commit 5887967

Please sign in to comment.