Skip to content

Commit

Permalink
WIP: working am and termux-tools
Browse files Browse the repository at this point in the history
  • Loading branch information
t184256 committed Jun 1, 2024
1 parent 2d93311 commit 7bcaa7b
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 0 deletions.
15 changes: 15 additions & 0 deletions modules/environment/am.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2019-2022, see AUTHORS. Licensed under MIT License, see LICENSE.

{ pkgs, ... }:

let
termux-am = pkgs.callPackage (import ../../pkgs/am/termux-am.nix) {};
termux-tools = pkgs.callPackage (import ../../pkgs/am/termux-tools.nix) {
inherit termux-am;
};
in
{
config = {
environment.packages = [ termux-am termux-tools ];
};
}
1 change: 1 addition & 0 deletions modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[
./build/activation.nix
./build/config.nix
./environment/am.nix
./environment/ca.nix
./environment/etc
./environment/links.nix
Expand Down
32 changes: 32 additions & 0 deletions pkgs/am/termux-am.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE.

{ stdenv, fetchFromGitHub, cmake }:

let
appPath = "/data/data/com.termux.nix/files/apps/com.termux.nix";
socketPath = "${appPath}/termux-am/am.sock";
in
stdenv.mkDerivation rec {
name = "termux-am";
version = "1.5.0";
src = fetchFromGitHub {
owner = "termux";
repo = "termux-am-socket";
rev = version;
sha256 = "sha256-6pCv2HMBRp8Hi56b43mQqnaFaI7y5DfhS9gScANwg2I=";
};
nativeBuildInputs = [ cmake ];
patchPhase = ''
# Header generation doesn't seem to work on android
echo "#define SOCKET_PATH \"${socketPath}\"" > termux-am.h
cat termux-am.h
# Fix the bash link so that nix can patch it
substituteInPlace termux-am.sh.in --replace @TERMUX_PREFIX@ ""
head termux-am.sh.in
'';
postInstall = ''
# Scripts use 'am' as an alias.
ln -s $out/bin/termux-am $out/bin/am
'';
}
31 changes: 31 additions & 0 deletions pkgs/am/termux-tools.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE.

{ stdenv, fetchFromGitHub, autoreconfHook, makeWrapper, gnused,
getopt, pandoc, termux-am }:

stdenv.mkDerivation rec {
name = "termux-tools";
version = "1.42.0";
src = fetchFromGitHub {
owner = "termux";
repo = "termux-tools";
rev = "v${version}";
sha256 = "sha256-/Yif1EbexA+eyNlK2cHDkck6P4R9Kr7pYyfJu25mGOA=";
};
nativeBuildInputs = [ autoreconfHook makeWrapper pandoc ];
propagatedInputs = [ termux-am ];
patches = [ ./termux-tools.patch ];
postPatch = ''
substituteInPlace scripts/* --replace @TERMUX_APP_PACKAGE@/ com.termux.nix/
substituteInPlace scripts/* --replace "getopt " "${getopt}/bin/getopt "
${gnused}/bin/sed -i 's|^am |${termux-am}/bin/am |' scripts/*
'';
postInstall = ''
mv $out out-back
mkdir -p $out/bin
rm out-back/bin/termux-reset
for script in out-back/bin/termux-*; do
install $script $out/bin/
done
'';
}
79 changes: 79 additions & 0 deletions pkgs/am/termux-tools.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
commit 6d72b44d90347ddce8473b604c38f352e6773f8d
Author: Alexander Sosedkin <[email protected]>
Date: Sat Jun 1 17:14:22 2024 +0200

scripts: replace com.termux with @TERMUX_APP_PACKAGE@

diff --git a/scripts/termux-open.in b/scripts/termux-open.in
index 9c81630..9a04e7b 100644
--- a/scripts/termux-open.in
+++ b/scripts/termux-open.in
@@ -44,7 +44,7 @@ case "${TERMUX__USER_ID:-}" in ''|*[!0-9]*|0[0-9]*) TERMUX__USER_ID=0;; esac

am broadcast --user "$TERMUX__USER_ID" \
-a $ACTION \
- -n com.termux/com.termux.app.TermuxOpenReceiver \
+ -n @TERMUX_APP_PACKAGE@/@[email protected] \
$EXTRAS \
-d "$FILE" \
> /dev/null
diff --git a/scripts/termux-reload-settings.in b/scripts/termux-reload-settings.in
index 4e71f8a..ef8b0f4 100644
--- a/scripts/termux-reload-settings.in
+++ b/scripts/termux-reload-settings.in
@@ -11,4 +11,4 @@ fi

case "${TERMUX__USER_ID:-}" in ''|*[!0-9]*|0[0-9]*) TERMUX__USER_ID=0;; esac

-am broadcast --user "$TERMUX__USER_ID" -a com.termux.app.reload_style com.termux > /dev/null
+am broadcast --user "$TERMUX__USER_ID" -a @[email protected]_style @TERMUX_APP_PACKAGE@ > /dev/null
diff --git a/scripts/termux-reset.in b/scripts/termux-reset.in
index 6f807a7..2161d1f 100644
--- a/scripts/termux-reset.in
+++ b/scripts/termux-reset.in
@@ -45,6 +45,6 @@ else
/system/bin/killall -9 "$SHELL"
else
export CLASSPATH="@TERMUX_CACHE_DIR@/termux-am/am.apk"
- /system/bin/app_process / com.termux.termuxam.Am stopservice com.termux/.app.TermuxService
+ /system/bin/app_process / @[email protected] stopservice @TERMUX_APP_PACKAGE@/.app.TermuxService
fi
fi
diff --git a/scripts/termux-setup-storage.in b/scripts/termux-setup-storage.in
index c621234..a086159 100644
--- a/scripts/termux-setup-storage.in
+++ b/scripts/termux-setup-storage.in
@@ -27,5 +27,5 @@ fi
case "${TERMUX__USER_ID:-}" in ''|*[!0-9]*|0[0-9]*) TERMUX__USER_ID=0;; esac

am broadcast --user "$TERMUX__USER_ID" \
- --es com.termux.app.reload_style storage \
- -a com.termux.app.reload_style com.termux > /dev/null
+ --es @[email protected]_style storage \
+ -a @[email protected]_style @TERMUX_APP_PACKAGE@ > /dev/null
diff --git a/scripts/termux-wake-lock.in b/scripts/termux-wake-lock.in
index ba4b899..f3fd59e 100644
--- a/scripts/termux-wake-lock.in
+++ b/scripts/termux-wake-lock.in
@@ -10,6 +10,6 @@ case "${TERMUX__USER_ID:-}" in ''|*[!0-9]*|0[0-9]*) TERMUX__USER_ID=0;; esac

am startservice \
--user "$TERMUX__USER_ID" \
- -a com.termux.service_wake_lock \
- com.termux/com.termux.app.TermuxService \
+ -a @[email protected]_wake_lock \
+ @TERMUX_APP_PACKAGE@/@[email protected] \
> /dev/null
diff --git a/scripts/termux-wake-unlock.in b/scripts/termux-wake-unlock.in
index a4b1f57..d53ce31 100644
--- a/scripts/termux-wake-unlock.in
+++ b/scripts/termux-wake-unlock.in
@@ -10,6 +10,6 @@ case "${TERMUX__USER_ID:-}" in ''|*[!0-9]*|0[0-9]*) TERMUX__USER_ID=0;; esac

am startservice \
--user "$TERMUX__USER_ID" \
- -a com.termux.service_wake_unlock \
- com.termux/com.termux.app.TermuxService \
+ -a @[email protected]_wake_unlock \
+ @TERMUX_APP_PACKAGE@/@[email protected] \
> /dev/null

0 comments on commit 7bcaa7b

Please sign in to comment.