The Salesforce migration tool can be used to migrate data between different Salesforce Organizations. It is essentially a JAR file which can be used as a plugin to Ant.
The challenge
The following post shows a small Nix snippet which provides the tool into an environment based on nix-shell. This snippet can be placed as a file called default.nix inside of the repository which contains the metadata files for an easy workflow.
The approach
My idea was that I just need two things:
- Apache Ant
- The JAR file with the migration tool
I could then use shellHook to set the environment variable CLASSPATH, so that Ant would find the needed extensions.
The result
{ pkgs ? (import <nixpkgs> {}) }: let ant-salesforce = pkgs.stdenv.mkDerivation rec { name = "ant-salesforce-${version}"; version = "37.0"; src = pkgs.fetchurl { url = "https://gs0.salesforce.com/dwnld/SfdcAnt/salesforce_ant_${version}.zip"; sha256 = "1jgvgrvxrms9rniqsn78blx0qm83kkzq1qcwcdizrn9x95x7i04p"; }; buildInputs = [ pkgs.unzip ]; installPhase = '' mkdir -p $out/share/java cp ../*.jar $out/share/java ''; meta = { homepage = https://developer.salesforce.com/docs/atlas.en-us.daas.meta/daas/meta_development.htm; description = "The Salesforce Migration Tool"; }; }; tooling = pkgs.stdenv.mkDerivation { name = "tooling"; src = null; buildInputs = [ pkgs.ant ant-salesforce ]; shellHook = '' export CLASSPATH=${ant-salesforce}/share/java/ant-salesforce.jar ''; buildPhase = '' echo "Not implemented" exit 1 ''; }; in tooling
How to use it
Make sure Nix is installed
See https://nixos.org/nix regarding installation instructions
Place the snippet into a file called default.nix
Run nix-shell
Now ant should be available and the environment variable CLASSPATH should be set up. To get started with the migration tool, you will need a file build.xml which defines the tasks. More details regarding this can be found in the Salesforce documentation, currently at https://developer.salesforce.com/docs/atlas.en-us.daas.meta/daas/meta_development.htm.