Skip to content

Commit

Permalink
ib tws latest
Browse files Browse the repository at this point in the history
  • Loading branch information
Czichy committed Mar 3, 2025
1 parent 5cbf967 commit 67fc987
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 48 deletions.
73 changes: 69 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
};

# --- UTILITIES -------------------------------------------------
nur = {
url = "github:nix-community/NUR";
inputs.nixpkgs.follows = "nixpkgs";
};
nixGL = {
url = "github:nix-community/nixGL";
inputs.nixpkgs.follows = "nixpkgs";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ in {

home.sessionVariables = {
# Default programs
BROWSER = _ "firefox";
BROWSER = _ "vivaldi";
EXPLORER = _ "yazi";
# TERMINAL = _ "foot";
EDITOR = _ "hx";
Expand Down
4 changes: 3 additions & 1 deletion modules/home-manager/programs/ib-tws.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ in {
# |----------------------------------------------------------------------| #
{
home.packages = [
inputs.self.packages.${system}.ib-tws-native
# inputs.self.packages.${system}.ib-tws-native
inputs.self.packages.${system}.ib-tws-native-latest
# pkgs.nur.repos.clefru.ib-tws
];
}
# |----------------------------------------------------------------------| #
Expand All @@ -95,6 +96,7 @@ in {
allowOther = true;
directories = [
".ib-tws-native"
".tws-latest"
".ib-tws-native_latest"
];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ in {
];
exec-once = [
# Startup
"swayosd-server"
# "swaybg -i ${wallpaper} --mode fill"
"${pkgs.swaynotificationcenter}/bin/swaync"
# "[workspace 7] firefox -P 'tradingview1' --class=tradingview"
Expand Down Expand Up @@ -164,8 +165,8 @@ in {
"SUPER + SHIFT,comma,movetoworkspacesilent,-1"
"SUPER + SHIFT,period,movetoworkspacesilent,+1"

", XF86AudioMute, exec, swayosd --output-volume mute-toggle"
", XF86AudioMicMute, exec, swayosd --input-volume mute-toggle"
", XF86AudioMute, exec, swayosd-client --output-volume mute-toggle"
", XF86AudioMicMute, exec, swayosd-client --input-volume mute-toggle"

# Special Workspaces
"SUPER,u,togglespecialworkspace"
Expand All @@ -179,10 +180,10 @@ in {
]);

bindle = [
", XF86AudioRaiseVolume, exec, swayosd --output-volume raise"
", XF86AudioLowerVolume, exec, swayosd --output-volume lower"
"SHIFT, XF86AudioRaiseVolume, exec, swayosd --input-volume raise"
"SHIFT, XF86AudioLowerVolume, exec, swayosd --input-volume lower"
", XF86AudioRaiseVolume, exec, swayosd-client --output-volume raise"
", XF86AudioLowerVolume, exec, swayosd-client --output-volume lower"
"SHIFT, XF86AudioRaiseVolume, exec, swayosd-client--input-volume raise"
"SHIFT, XF86AudioLowerVolume, exec, swayosd-client--input-volume lower"
];

bindm = [
Expand Down
2 changes: 2 additions & 0 deletions parts/pkgs/ibtws/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ in
etagHash = "sha256-l8532dQIgUlN9L++3Y8qLeRu9/vof2/aMLySXZlq4hw=";

src = fetchurl {
# url = "https://download2.interactivebrokers.com/installers/tws/latest-standalone/tws-latest-standalone-linux-x64.sh";
# sha256 = "sha256-bpFKD1l8PwAV2g7MjApg3QC0TAO76VPHLiI5rGcfcSs=";
url = "https://download2.interactivebrokers.com/installers/tws/stable-standalone/tws-stable-standalone-linux-x64.sh";
hash = "sha256-ueRlda7oHAHnmU5iVHvu+06Omf9InVIczL0QAfL4jyw=";
};
Expand Down
16 changes: 8 additions & 8 deletions parts/pkgs/ibtws_latest/default.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{pkgs ? import <nixpkgs> {}}:
with pkgs; let
jdkWithJavaFX = pkgs.jdk21.override {
jdkWithJavaFX = pkgs.jdk23.override {
enableJavaFX = true;
openjfx21 = openjfx.override {withWebKit = true;};
openjfx23 = openjfx.override {withWebKit = true;};
};
ibDerivation = stdenv.mkDerivation rec {
version = "10.34.1c";
pname = "ib-tws-native";
pname = "ib-tws-latest";

src = fetchurl {
url = "https://download2.interactivebrokers.com/installers/tws/latest-standalone/tws-latest-standalone-linux-x64.sh";
Expand Down Expand Up @@ -47,9 +47,9 @@ with pkgs; let
# -Dsun.java2d.opengl=False not applied. Why would I disable that?
# -Dswing.aatext=true applied
mkdir $out/bin
sed -e s#__OUT__#$out# -e s#__JAVAHOME__#${jdkWithJavaFX.home}# -e s#__GTK__#${pkgs.gtk3}# -e s#__CCLIBS__#${pkgs.stdenv.cc.cc.lib}# ${./tws-wrap.sh} > $out/bin/ib-tws-native
sed -e s#__OUT__#$out# -e s#__JAVAHOME__#${jdkWithJavaFX.home}# -e s#__GTK__#${pkgs.gtk3}# -e s#__CCLIBS__#${pkgs.stdenv.cc.cc.lib}# ${./tws-wrap.sh} > $out/bin/ib-tws-latest
chmod a+rx $out/bin/ib-tws-native
chmod a+rx $out/bin/ib-tws-latest
# FIXME Fixup .desktop starter.
'';
Expand All @@ -62,13 +62,13 @@ with pkgs; let
platforms = platforms.linux;
};
};
# IB TWS packages the JxBrowser component. It unpacks a pre-built
# IB TWS packages the JxBrowser component. It unpacks a prelatest
# Chromium binary (yikes!) that needs an FHS environment. For me, that
# doesn't yet work, and the chromium fails to launch with an error
# code.
in
buildFHSUserEnv {
name = "ib-tws";
name = "ib-tws-latest";
targetPkgs = pkgs1: [
ibDerivation

Expand Down Expand Up @@ -99,7 +99,7 @@ in
libxkbcommon
systemd # for libudev.so.1
];
runScript = "/usr/bin/ib-tws-native";
runScript = "env QT_SCALE_FACTOR=2 /usr/bin/ib-tws-latest";
}
# {
# stdenv,
Expand Down
1 change: 1 addition & 0 deletions parts/pkgs/ibtws_latest/tws-wrap.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh
export INSTALL4J_JAVA_HOME_OVERRIDE='__JAVAHOME__'
export GDK_BACKEND=x11
mkdir -p $HOME/.tws-latest
VMOPTIONS=$HOME/.tws-latest/tws.vmoptions
if [ ! -e tws.vmoptions ]; then
Expand Down
77 changes: 49 additions & 28 deletions parts/pkgs/ibtws_latest/update.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,55 @@
i#!/bin/sh
cd $(dirname $0)
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl gnused gnugrep

URL_PREFIX=https://download2.interactivebrokers.com/installers/tws/latest-standalone
URL_JSON=${URL_PREFIX}/version.json
URL_INSTALLER=${URL_PREFIX}/tws-latest-standalone-linux-x64.sh
set -eu -o pipefail

UPSTREAM_VERSION=$(curl ${URL_JSON} | sed 's/twslatest_callback({"buildVersion":"\(.*\)","buildDateTime.*/\1/')
LOCAL_VERSION=$(grep -Po 'version = "\K([^"]*)' default.nix)
dirname=$(dirname "$0" | xargs realpath)
nixpkgs=$(realpath "${dirname}/../..")
attr=ib-tws
nix_file="$dirname/default.nix"

if [ "$1" == "--no-git" ]; then
GIT="true";
else
GIT="git";
url="https://download2.interactivebrokers.com/installers/tws/latest-standalone/tws-latest-standalone-linux-x64.sh"
latestEtagHash=$(curl -sI $url | grep ETag | sed -E 's/.*"([^:]+):.*/\1/')

currentEtagHash=$(nix-instantiate --eval -E "with import $nixpkgs {}; $attr.etagHash or (builtins.parseDrvName $attr.name).etagHash" | tr -d '"')
currentVersion=$(nix-instantiate --eval -E "with import $nixpkgs {}; $attr.version or (builtins.parseDrvName $attr.name).version" | tr -d '"')

if [ "$currentEtagHash" = "$latestEtagHash" ]; then
echo "ib-tws is up-to-date: ${currentVersion}"
exit 0
fi

if [ "$UPSTREAM_VERSION" != "$LOCAL_VERSION" -a -n "$UPSTREAM_VERSION" ]; then
$GIT pull --rebase
if [ -z "$(git status --untracked-files=no --porcelain)" ]; then
$GIT stash
CLEANUP="$GIT stash pop"
fi
FILE=$(mktemp)
curl ${URL_INSTALLER} > $FILE
chmod a+x $FILE
HASH=$(nix-hash $FILE --type sha256 --base32)
rm $FILE
sed -i -e 's/version = ".*/version = "'$UPSTREAM_VERSION'";/' default.nix
sed -i -e 's/sha256 = ".*/sha256 = "'$HASH'";/' default.nix
$GIT add default.nix
$GIT commit -m "ib-tws: $LOCAL_VERSION -> $UPSTREAM_VERSION"
eval $CLEANUP
$GIT push
# download install script, get hash and store path
{
read hash
read installScriptPath
} < <(nix-prefetch-url "$url" --type sha256 --print-path)

# convert to SRI hash
sriHash=$(nix hash to-sri --type sha256 $hash)

# extract install script to extract the version string
src="$(mktemp -d /tmp/ib-tws-src.XXX)"
pushd "$src"

INSTALL4J_TEMP="$src" sh "$installScriptPath" __i4j_extract_and_exit
latestVersion=$(grep buildInfo "$src/"*.dir/i4jparams.conf | sed -E 's/.*name="buildInfo" value="Build (\S+) .*/\1/')

popd
rm -r "$src"

# update hash, version and etagHash
sed -E \
-e "s|hash = \"[a-zA-Z0-9\/+-=]*\";|hash = \"$sriHash\";|" \
-e "s|version = \"$currentVersion\";|version = \"$latestVersion\";|" \
-e "s|etagHash = \"$currentEtagHash\";|etagHash = \"$latestEtagHash\";|" \
-i "$nix_file"

# prepare a commit for automation
cmd=`echo "git commit -a -m \"$attr: $currentVersion -> $latestVersion\""`

if [ -n "$GITHUB_ACTION" ]; then
eval $cmd
else
echo $cmd
fi

0 comments on commit 67fc987

Please sign in to comment.