-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.nix
107 lines (98 loc) · 2.89 KB
/
module.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# NixOS module for the `icloud-biff` service, that monitors an iCloud shared
# photo library, and emails when there are new updates.
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.icloud-biff;
in
{
#
# Configuration options
#
options.services.icloud-biff = {
enable = mkEnableOption "Periodically monitor an iCloud shared photo library";
interval = mkOption {
type = types.str;
default = "hourly";
example = "daily";
description = ''
How long to wait between sending updates.
'';
};
album-name = mkOption {
type = types.str;
example = "My pretty dogs";
description = ''
Name of photo album to reference in update emails.
'';
};
album-id = mkOption {
type = types.str;
example = "B0tXbaIORGhww3a";
description = ''
Photo album identifier - taken from the website URL
(https://www.icloud.com/sharedalbum/#<ALBUM-ID-HERE>
'';
};
recipient-email-addrs = mkOption {
type = types.listOf types.str;
example = "[ [email protected] [email protected] ]";
description = ''
List of email recipients. This should just be the pure email address,
eg "[email protected]" is good, but "My Mum <[email protected]>" is bad.
'';
};
sender-email-addr = mkOption {
type = types.str;
example = "[email protected]";
description = ''
Email address to use as the From: address when sending email.
'';
};
sender-email-name = mkOption {
type = types.str;
example = "Helpful Photo Update Robot";
description = ''
Human-readable name to use as the From: address when sending email.
'';
};
};
#
# Implementation - use cron rather than systemd for now, to get easy emails
# if something goes squiffy.
#
config =
let
config-file-contents = cfg // {
sendmail-path = "/run/wrappers/bin/sendmail";
db-file = "/var/lib/icloud-biff/seen-gids.json";
};
config-file = pkgs.writeText "icloud-biff-config.json" (builtins.toJSON config-file-contents);
in
mkIf cfg.enable {
# Database directory
systemd.tmpfiles.rules = [
"d /var/lib/icloud-biff 0755 icloud-biff icloud-biff"
];
# Service
systemd.services.icloud-biff = {
description = "Monitor iCloud shared photo library";
after = [ "network-online.target" ];
startAt = cfg.interval;
serviceConfig = {
ExecStart = "${pkgs.icloud-biff}/bin/icloud-biff --config ${config-file}";
User = "icloud-biff";
Group = "icloud-biff";
};
};
# User/group
users = {
users.icloud-biff = {
description = "User to monitor iCloud photo library";
group = "icloud-biff";
isSystemUser = true;
};
groups.icloud-biff = { };
};
};
}