diff --git a/pkgs/default.nix b/pkgs/default.nix index 6339da3..255a365 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -5,6 +5,7 @@ in { override = {}; athena-bccr = callPackage ./athena-bccr {vendor = "athena";}; + ibkr-tws = callPackage ./ibkr-tws {}; idopte-bccr = callPackage ./athena-bccr {vendor = "idopte";}; snapborg = final.python3Packages.callPackage ./snapborg {}; socialpredict = callPackage ./socialpredict {}; diff --git a/pkgs/ibkr-tws/default.nix b/pkgs/ibkr-tws/default.nix new file mode 100644 index 0000000..ea3e94b --- /dev/null +++ b/pkgs/ibkr-tws/default.nix @@ -0,0 +1,106 @@ +{ + lib, + makeWrapper, + openjdk, + requireFile, + stdenv, +}: let + version = "10.44.1g"; + + jdk = openjdk.override { + enableJavaFX = true; + }; + + removeJavaVersionCheck = file: '' + # Lie about the openjdk version to skip the version check + sed -i 's/\(read_db_entry || create_db_entry \$2\)/\1; ver_major=17; ver_minor=0; ver_micro=16/' ${file} + ''; +in + stdenv.mkDerivation { + pname = "ibkr-tws"; + inherit version; + + src = requireFile { + name = "tws-${version}-standalone-linux-x64.sh"; + url = "https://www.interactivebrokers.com/en/trading/download-tws.php?p=offline-latest"; + + # 1. Rename 'tws-latest-standalone-linux-x64.sh' to 'tws-${version}-standalone-linux-x64.sh' + # 2. nix hash convert --hash-algo sha256 --from base16 --to sri $(sha256sum tws-${version}-standalone-linux-x64.sh | cut -d' ' -f1) + hash = "sha256-UfyfTHOcPiwTof0ZMhV1haX7gyb08v7U2A12VjAny7c="; + }; + + nativeBuildInputs = [ + makeWrapper + ]; + + unpackPhase = '' + runHook preUnpack + + cp $src bundle.sh + chmod +x bundle.sh + + runHook postUnpack + ''; + + patchPhase = '' + runHook prePatch + + ${removeJavaVersionCheck "bundle.sh"} + + runHook postPatch + ''; + + preBuild = '' + export INSTALL4J_NO_DB=true + export INSTALL4J_JAVA_HOME=${jdk} + export INSTALL4J_DISABLE_BUNDLED_JRE=true + ''; + + buildPhase = '' + runHook preBuild + + # Where should Trader Workstation 10.44 be installed?: $out + # Run Trader Workstation 10.44? Yes [y], No [n, Enter]: n + echo -e "$out/lib/tws\nn" | ./bundle.sh + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + mkdir -p "$out/bin" "$out/share/applications" + + ${removeJavaVersionCheck "$out/lib/tws/tws"} + makeWrapper \ + "$out/lib/tws/tws" "$out/bin/tws" \ + --set INSTALL4J_NO_DB true \ + --set INSTALL4J_JAVA_HOME ${jdk} + + mv "$out/lib/tws/.install4j/tws.png" "$out/lib/tws" + + for path in $out/lib/tws/*.desktop; do + target="$(readlink -f "$path")" + mv "$target" "$out/share/applications/$(basename "$path")" + rm -f "$path" + done + + sed -i \ + 's@$out/lib/tws/tws\>@$out/bin/tws@; s@$out/lib/tws/.install4j/tws.png@$out/lib/tws/tws.png@' \ + $out/share/applications/*.desktop + + #TODO + sed -i \ + 's@/build/Jts@/tmp/Jts@g' \ + $out/lib/tws/.install4j/{i4jparams.conf,response.varfile} + + rm -f "$out/lib/tws/uninstall" $out/lib/tws/.install4j/*.log + + runHook postInstall + ''; + + meta = { + license = lib.licenses.unfree; + mainProgram = "tws"; + }; + }