From 90a326eecd8988abe82b14168c894f5e3a72d407 Mon Sep 17 00:00:00 2001 From: Attila Sztupak Date: Fri, 26 Sep 2014 15:33:36 +0100 Subject: [PATCH] crashplan: nixos module for backup service --- nixos/modules/module-list.nix | 1 + nixos/modules/services/backup/crashplan.nix | 63 +++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 nixos/modules/services/backup/crashplan.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index deec9fd1bb77..470b78381988 100755 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -92,6 +92,7 @@ ./services/audio/mopidy.nix ./services/backup/almir.nix ./services/backup/bacula.nix + ./services/backup/crashplan.nix ./services/backup/mysql-backup.nix ./services/backup/postgresql-backup.nix ./services/backup/rsnapshot.nix diff --git a/nixos/modules/services/backup/crashplan.nix b/nixos/modules/services/backup/crashplan.nix new file mode 100644 index 000000000000..1862709b1365 --- /dev/null +++ b/nixos/modules/services/backup/crashplan.nix @@ -0,0 +1,63 @@ +{ config, pkgs, ... }: + +let + cfg = config.services.crashplan; + crashplan = pkgs.crashplan; + varDir = "/var/lib/crashplan"; +in + +with pkgs.lib; + +{ + options = { + services.crashplan = { + enable = mkOption { + default = false; + type = types.bool; + description = '' + Starts crashplan background service. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + environment.systemPackages = [ crashplan ]; + + systemd.services.crashplan = { + description = "CrashPlan Backup Engine"; + + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + + preStart = '' + ensureDir() { + dir=$1 + mode=$2 + + if ! test -e $dir; then + ${pkgs.coreutils}/bin/mkdir -m $mode -p $dir + elif [ "$(${pkgs.coreutils}/bin/stat -c %a $dir)" != "$mode" ]; then + ${pkgs.coreutils}/bin/chmod $mode $dir + fi + } + + ensureDir ${crashplan.vardir} 755 + ensureDir ${crashplan.vardir}/conf 700 + ensureDir ${crashplan.manifestdir} 700 + ensureDir ${crashplan.vardir}/cache 700 + ensureDir ${crashplan.vardir}/backupArchives 700 + ensureDir ${crashplan.vardir}/log 777 + ''; + + serviceConfig = { + Type = "forking"; + EnvironmentFile = "${crashplan}/bin/run.conf"; + ExecStart = "${crashplan}/bin/CrashPlanEngine start"; + ExecStop = "${crashplan}/bin/CrashPlanEngine stop"; + PIDFile = "${crashplan.vardir}/CrashPlanEngine.pid"; + WorkingDirectory = crashplan; + }; + }; + }; +} \ No newline at end of file