Skip to content

Instantly share code, notes, and snippets.

@danidiaz
Last active February 23, 2023 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danidiaz/68bd660562f95afd09c8980f02fc0fd5 to your computer and use it in GitHub Desktop.
Save danidiaz/68bd660562f95afd09c8980f02fc0fd5 to your computer and use it in GitHub Desktop.
Wiremock shell.nix
# https://wiremock.org/docs/running-standalone/
# inspired by https://discourse.nixos.org/t/download-and-wrap-a-jar-extensively-documented-example/8049
{ pkgs ? import <nixpkgs> {} }:
let mywiremock =
pkgs.stdenv.mkDerivation rec {
name = "mywiremock";
version = "2.35.0";
# https://ryantm.github.io/nixpkgs/builders/fetchers/
src = pkgs.fetchurl {
url = "https://repo1.maven.org/maven2/com/github/tomakehurst/wiremock-jre8-standalone/2.35.0/wiremock-jre8-standalone-2.35.0.jar";
sha256 = "sha256-rhVq4oEuPPpHDEftBzEA707HeSc3Kk4gPw471THz61c=";
};
# I fetch the JAR file directly, so no archives to unpack.
dontUnpack = true;
# https://nixos.org/manual/nixpkgs/stable/#fun-makeWrapper
nativeBuildInputs = [ pkgs.makeWrapper ];
# wiremock doesn't work with jre_minimal
installPhase = ''
mkdir -pv $out/share/java $out/bin
cp ${src} $out/share/java/wiremock-jre8-standalone-2.35.0.jar
makeWrapper ${pkgs.jre}/bin/java $out/bin/mywiremock \
--add-flags "-jar $out/share/java/wiremock-jre8-standalone-2.35.0.jar"
'';
};
in
pkgs.mkShell {
packages = [
pkgs.jre
# extra arguments are passed to the wrapped program, like mywiremock --record-mappings
mywiremock
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment