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