1{ config, pkgs, lib, ... }:
2
3let
4 cfg = config.services.crashplansb;
5 crashplansb = pkgs.crashplansb.override { maxRam = cfg.maxRam; };
6 varDir = "/var/lib/crashplan";
7in
8
9with lib;
10
11{
12 options = {
13 services.crashplansb = {
14 enable = mkOption {
15 default = false;
16 type = types.bool;
17 description = ''
18 Starts crashplan for small business background service.
19 '';
20 };
21 maxRam = mkOption {
22 default = "1024m";
23 example = "2G";
24 type = types.str;
25 description = ''
26 Maximum amount of ram that the crashplan engine should use.
27 '';
28 };
29 openPorts = mkOption {
30 description = "Open ports in the firewall for crashplan.";
31 default = true;
32 type = types.bool;
33 };
34 ports = mkOption {
35 # https://support.code42.com/Administrator/6/Planning_and_installing/TCP_and_UDP_ports_used_by_the_Code42_platform
36 # used ports can also be checked in the desktop app console using the command connection.info
37 description = "which ports to open.";
38 default = [ 4242 4243 4244 4247 ];
39 type = types.listOf types.int;
40 };
41 };
42 };
43
44 config = mkIf cfg.enable {
45 environment.systemPackages = [ crashplansb ];
46 networking.firewall.allowedTCPPorts = mkIf cfg.openPorts cfg.ports;
47
48 systemd.services.crashplansb = {
49 description = "CrashPlan Backup Engine";
50
51 wantedBy = [ "multi-user.target" ];
52 after = [ "network.target" "local-fs.target" ];
53
54 preStart = ''
55 install -d -m 755 ${crashplansb.vardir}
56 install -d -m 700 ${crashplansb.vardir}/conf
57 install -d -m 700 ${crashplansb.manifestdir}
58 install -d -m 700 ${crashplansb.vardir}/cache
59 install -d -m 700 ${crashplansb.vardir}/backupArchives
60 install -d -m 777 ${crashplansb.vardir}/log
61 cp -avn ${crashplansb}/conf.template/* ${crashplansb.vardir}/conf
62 '';
63
64 serviceConfig = {
65 Type = "forking";
66 EnvironmentFile = "${crashplansb}/bin/run.conf";
67 ExecStart = "${crashplansb}/bin/CrashPlanEngine start";
68 ExecStop = "${crashplansb}/bin/CrashPlanEngine stop";
69 PIDFile = "${crashplansb.vardir}/CrashPlanEngine.pid";
70 WorkingDirectory = crashplansb;
71 };
72 };
73 };
74}