From f24b642587db32d0e857e398e54831550bfb6556 Mon Sep 17 00:00:00 2001 From: Marti Serra Date: Sun, 17 Dec 2017 14:11:54 +0100 Subject: [PATCH] crashplan-small-business: init at 6.6.0 --- nixos/modules/module-list.nix | 1 + .../backup/crashplan-small-business.nix | 89 +++++++++++++++ .../crashplan/crashplan-small-business.nix | 102 ++++++++++++++++++ pkgs/top-level/all-packages.nix | 1 + 4 files changed, 193 insertions(+) create mode 100644 nixos/modules/services/backup/crashplan-small-business.nix create mode 100644 pkgs/applications/backup/crashplan/crashplan-small-business.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index bc03b3dae399..f830b486ca0a 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -147,6 +147,7 @@ ./services/backup/almir.nix ./services/backup/bacula.nix ./services/backup/crashplan.nix + ./services/backup/crashplan-small-business.nix ./services/backup/mysql-backup.nix ./services/backup/postgresql-backup.nix ./services/backup/rsnapshot.nix diff --git a/nixos/modules/services/backup/crashplan-small-business.nix b/nixos/modules/services/backup/crashplan-small-business.nix new file mode 100644 index 000000000000..c6002b6a3f6b --- /dev/null +++ b/nixos/modules/services/backup/crashplan-small-business.nix @@ -0,0 +1,89 @@ +{ config, pkgs, lib, ... }: + +let + cfg = config.services.crashplansb; + crashplansb = pkgs.crashplansb.override { maxRam = cfg.maxRam; }; + varDir = "/var/lib/crashplan"; +in + +with lib; + +{ + options = { + services.crashplansb = { + enable = mkOption { + default = false; + type = types.bool; + description = '' + Starts crashplan for small business background service. + ''; + }; + maxRam = mkOption { + default = "1024m"; + example = "2G"; + type = types.str; + description = '' + Maximum amount of that the crashplan engine should use. + ''; + }; + openPorts = mkOption { + description = "Open ports in the firewall for crashplan."; + default = true; + type = types.bool; + }; + ports = mkOption { + # https://support.code42.com/Administrator/6/Planning_and_installing/TCP_and_UDP_ports_used_by_the_Code42_platform + # used ports can also be checked in the desktop app console using the command connection.info + description = "which ports to open."; + default = [ 4242 4243 4244 4247 ]; + type = types.listOf types.int; + }; + }; + }; + + config = mkIf cfg.enable { + environment.systemPackages = [ crashplansb ]; + networking.firewall.allowedTCPPorts = mkIf cfg.openPorts cfg.ports; + + systemd.services.crashplansb = { + description = "CrashPlan Backup Engine"; + + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" "local-fs.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 ${crashplansb.vardir} 755 + ensureDir ${crashplansb.vardir}/conf 700 + ensureDir ${crashplansb.manifestdir} 700 + ensureDir ${crashplansb.vardir}/cache 700 + ensureDir ${crashplansb.vardir}/backupArchives 700 + ensureDir ${crashplansb.vardir}/log 777 + cp -avn ${crashplansb}/conf.template/* ${crashplansb.vardir}/conf + #for x in bin install.vars lang lib libc42archive64.so libc42core.so libjniwrap64.so libjtux64.so libleveldb64.so libnetty-tcnative.so share upgrade; do + # rm -f ${crashplansb.vardir}/$x; + # ln -sf ${crashplansb}/$x ${crashplansb.vardir}/$x; + #done + ''; + + serviceConfig = { + Type = "forking"; + EnvironmentFile = "${crashplansb}/bin/run.conf"; + ExecStart = "${crashplansb}/bin/CrashPlanEngine start"; + ExecStop = "${crashplansb}/bin/CrashPlanEngine stop"; + PIDFile = "${crashplansb.vardir}/CrashPlanEngine.pid"; + WorkingDirectory = crashplansb; + }; + }; + }; +} diff --git a/pkgs/applications/backup/crashplan/crashplan-small-business.nix b/pkgs/applications/backup/crashplan/crashplan-small-business.nix new file mode 100644 index 000000000000..cfcab1eea317 --- /dev/null +++ b/pkgs/applications/backup/crashplan/crashplan-small-business.nix @@ -0,0 +1,102 @@ +{ stdenv, fetchurl, makeWrapper, getopt, jre, cpio, gawk, gnugrep, gnused, + procps, which, gtk2, atk, glib, pango, gdk_pixbuf, cairo, freetype, + fontconfig, dbus, gconf, nss, nspr, alsaLib, cups, expat, libudev, + libX11, libxcb, libXi, libXcursor, libXdamage, libXrandr, libXcomposite, + libXext, libXfixes, libXrender, libXtst, libXScrnSaver, nodePackages, + maxRam ? "1024m" }: + +stdenv.mkDerivation rec { + version = "6.6.0"; + rev = "1506661200660_4347"; + pname = "CrashPlanSmb"; + name = "${pname}_${version}_${rev}"; + + src = fetchurl { + url = "https://web-eam-msp.crashplanpro.com/client/installers/${name}_Linux.tgz"; + sha256 = "1zzx60fpmi2nlzpq80x4hfgspsrgd7ycfcvc6w391wxr0qzf2i9k"; + }; + + nativeBuildInputs = [ makeWrapper cpio nodePackages.asar ]; + buildInputs = [ getopt which ]; + + vardir = "/var/lib/crashplan"; + manifestdir = "${vardir}/manifest"; + + postPatch = '' + # patch scripts/CrashPlanEngine + substituteInPlace scripts/CrashPlanEngine \ + --replace /bin/ps ${procps}/bin/ps \ + --replace awk ${gawk}/bin/awk \ + --replace '`sed' '`${gnused}/bin/sed' \ + --replace grep ${gnugrep}/bin/grep \ + --replace TARGETDIR/log VARDIR/log \ + --replace TARGETDIR/\''${NAME} VARDIR/\''${NAME} \ + --replace \$TARGETDIR/bin/run.conf $out/bin/run.conf \ + --replace \$VARDIR ${vardir} + + # patch scripts/CrashPlanDesktop + substituteInPlace scripts/CrashPlanDesktop \ + --replace awk ${gawk}/bin/awk \ + --replace "\"\$SCRIPTDIR/..\"" "$out" \ + --replace "\$(dirname \$SCRIPT)" "$out" \ + --replace "\''${TARGETDIR}/log" ${vardir}/log \ + --replace "\''${TARGETDIR}" "$out" + ''; + + installPhase = '' + mkdir $out + zcat -v ${pname}_${version}.cpi | (cd $out; cpio -i -d -v --no-preserve-owner) + + install -D -m 755 scripts/CrashPlanDesktop $out/bin/CrashPlanDesktop + install -D -m 755 scripts/CrashPlanEngine $out/bin/CrashPlanEngine + install -D -m 644 scripts/run.conf $out/bin/run.conf + install -D -m 644 scripts/CrashPlan.desktop $out/share/applications/CrashPlan.desktop + + # unpack, patch and repack app.asar to stop electron from creating /usr/local/crashplan/log to store the ui logs. + asar e $out/app.asar $out/app.asar-unpacked + rm -v $out/app.asar + substituteInPlace $out/app.asar-unpacked/shared_modules/shell/platform_paths.js \ + --replace "getLogFileParentPath();" "\"$vardir/log\";" + asar p $out/app.asar-unpacked $out/app.asar + + mv -v $out/*.asar $out/electron/resources + chmod 755 "$out/electron/crashplan" + + rm -r $out/log + mv -v $out/conf $out/conf.template + ln -s $vardir/log $out/log + ln -s $vardir/cache $out/cache + ln -s $vardir/conf $out/conf + + substituteInPlace $out/bin/run.conf \ + --replace "-Xmx1024m" "-Xmx${maxRam}" + + echo "JAVACOMMON=${jre}/bin/java" > $out/install.vars + echo "APP_BASENAME=CrashPlan" >> $out/install.vars + echo "TARGETDIR=$out" >> $out/install.vars + echo "BINSDIR=$out/bin" >> $out/install.vars + echo "MANIFESTDIR=${manifestdir}" >> $out/install.vars + echo "VARDIR=${vardir}" >> $out/install.vars + echo "INITDIR=" >> $out/install.vars + echo "RUNLVLDIR=" >> $out/install.vars + echo "INSTALLDATE=" >> $out/install.vars + + ''; + + postFixup = '' + patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux-x86-64.so.2 $out/electron/crashplan + wrapProgram $out/bin/CrashPlanDesktop --prefix LD_LIBRARY_PATH ":" "${stdenv.lib.makeLibraryPath [ + stdenv.cc.cc.lib gtk2 atk glib pango gdk_pixbuf cairo freetype + fontconfig dbus gconf nss nspr alsaLib cups expat libudev + libX11 libxcb libXi libXcursor libXdamage libXrandr libXcomposite + libXext libXfixes libXrender libXtst libXScrnSaver]}" + ''; + + meta = with stdenv.lib; { + description = "An online backup solution"; + homepage = http://www.crashplan.com/business/; + license = licenses.unfree; + maintainers = with maintainers; [ xvapx ]; + }; + +} \ No newline at end of file diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 315837087ed8..e3c4a79600c0 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -19261,6 +19261,7 @@ with pkgs; cups-toshiba-estudio = callPackage ../misc/cups/drivers/estudio {}; crashplan = callPackage ../applications/backup/crashplan { }; + crashplansb = callPackage ../applications/backup/crashplan/crashplan-small-business.nix { inherit (gnome3) gconf; }; colort = callPackage ../applications/misc/colort { };