-
@ shinohai
2024-06-30 19:13:18I rarely use smartphones for their intended purpose, instead using them as cheap and portable "mini machines" thanks to termux. Since joining nostr and learning how relays work, I got to wondering if running a relay from my test phone would be possible. After many hours of failed attempts and chairs thrown through windows, here's how I finally got python nostr_relay to work on my device.
YOU WILL NEED - An android device with latest Termux from FDROID OR GITHUB (The Google Play version will not work). You will need python 3.x,clang, and git installed in this environment.
Step 1. Start sshd in termux and log into your device.
Step 2. User must modify their python sysconfigdata manually, since the Android NDK with latest clang does not support the -fopenmp-implicit-rpath flag and will cause any .toml based python wheel builds to fail. Simply run the following commands in your termux terminal to fix this (A backup up your original sysconfig files will be saved, this example shows the steps being performed for python 3.11):
_file="$(find $PREFIX/lib/python3.11 -name "_sysconfigdata*.py")"
rm -rf $PREFIX/lib/python3.11/pycache
cp $_file "$_file".backup
sed -i 's|-fno-openmp-implicit-rpath||g' "$_file"Step 3. Make a directory for the install and switch to it, I am using "devel" in this example:
mkdir -p devel && cd $_
Step 4. Clone the nostr_relay repo, I have mirrored the latest version to Github for those that hate fossil as much as I do:
git clone https://github.com/Shinoa-Fores/nostr_relay.git
Step 5. Make a python virtual environment and activate it:
python3.11 -m venv nostr_relay
cd nostr_relay
source bin/activateStep 6. Pycares is a required dependency for toml-based projects, and also will not install properly via pip under termux so we will install it from sources in the venv and apply a quick fix to that too:
wget https://files.pythonhosted.org/packages/1b/8f/daf60bbc06f4a3cd1cfb0ab807057151287df6f5c78f2e0d298acc9193ac/pycares-4.4.0.tar.gz
tar -xf pycares-4.4.0.tar.gz
sed -i s/'#define HAVE_GETSERVBYPORT_R 1'//g ./pycares-4.4.0/deps/build-config/config_android/ares_config.h
pip install ./pycares-4.4.0
rm -rf pycares-4.4.0 pycares-4.4.0.tar.gzStep 7. Now install the remaining dependencies and nostr-Relay itself:
pip install -e .
Step 8. Make a cup of tea and shitpost on nostr until the build completes.
Step 9. Once build is finished, copy the included sample config and open in your preferred text editor to adjust the parameters to your liking:
cp nostr_relay/config.yaml .
Step 10. Make a startup script for the relay and fire up your portable relay. In the example below I start it in a screen session so the process does not die if I lose ssh or termux connection.
cat >start-relay.sh << EOF
!/usr/bin/env bash
set -eu
set -o pipefail
bin/nostr-relay -c ./config.yaml serve
EOFchmod +x start-relay.sh
screen -S relay -dm bash ./start-relay.sh
Step 11. If all goes well you should see something like this:
Still here? Good! The reader is invited to tinker with this configuration and enhance it. Things like setting up DNS and tor are beyond the scope of this post, but information on the latter can be found on the termux wiki: https://wiki.termux.com/wiki/Bypassing_NAT .