Skip to content

Instantly share code, notes, and snippets.

@tadfisher
Created January 28, 2020 21:59
Show Gist options
  • Save tadfisher/1007f68d321d6789dfd3b2301119f685 to your computer and use it in GitHub Desktop.
Save tadfisher/1007f68d321d6789dfd3b2301119f685 to your computer and use it in GitHub Desktop.
gradle2nix updateScript wrapper
{ callPackage, jre, makeWrapper }:
rec {
buildGradle = callPackage ./gradle-env.nix {};
gradle2nix = buildGradle {
envSpec = ./gradle-env.json;
src = import ./fetch-source.nix {};
gradleFlags = [ "installDist" ];
nativeBuildInputs = [ makeWrapper ];
installPhase = ''
mkdir -p $out
cp -r app/build/install/gradle2nix/* $out/
wrapProgram $out/bin/gradle2nix \
--set JAVA_HOME ${jre}
'';
};
gradleUpdateScript = callPackage ./update.nix {
inherit gradle2nix;
};
}
{ stdenv, coreutils, findutils, gradle2nix, nix, writeShellScript }:
# Name of the package
{ packageName
# Path in pkgs if different from packageName
, attrPath ? packageName
# Paths to add to the shell environment
, paths ? []
# Path to the root Gradle project, relative to the source root
, projectDir ? ""
# Name of output file in package directory
, outFile ? "gradle-env.json"
# Extra script to run prior to running gradle2nix (e.g. update package version)
, script ? ""
}:
let
path = stdenv.lib.makeBinPath (paths ++ [ coreutils findutils gradle2nix nix ]);
in writeShellScript "${packageName}-update-script" ''
OLDOPTS="$(set +o); set -''${-//c}"
export PATH="${path}''${PATH:+':'}$PATH"
${script}
set +vx; eval "''${OLDOPTS}"
set -eu -o pipefail
packageDir=$(nix-instantiate --eval --strict -A "$attrPath.meta.position" | sed -re 's/^"(.*):[0-9]+"$/\1/' | xargs dirname | xargs realpath)
nix-shell -A $attrPath
cd "$(mktemp --tmpdir -d ${packageName}.XXXX)"
unpackPhase
cd "$sourceRoot/${projectDir}"
gradle2nix --quiet
cp gradle-env.json "$packageDir/${outFile}"
exit
''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment