🧠 Self-Hosting a Nostr Relay on Raspberry Pi + Automating Reddit Posts with n8n & Python
In this post, I’ll walk through how I: Set up a self-hosted Nostr relay using Rust on a Raspberry Pi Wrote a Python bot (EGBot) to post content to my relay Automated Reddit → Nostr posting using n8n
🛠️ Part 1: Running a Self-Hosted Nostr Relay on Raspberry Pi
I started by deploying a Nostr relay using [the Rust implementation](<https://github.com/scsibug/nostr-rs-relay>) on a Raspberry Pi 5. It's lightweight and perfect for a low-power device.
🔧 Configuration
In my relay config config.toml
), I added two key restrictions to keep it clean and minimal:
1. Event Kind Allowlist
Only specific Nostr event kinds are accepted. Others are discarded.
event_kind_allowlist = [0, 1, 2, 3, 7, 40, 10002]
|
0
| Metadata | Stores user profile metadata:name
,about
,picture
, etc. This is the standard user profile event. ||
1
| Text Note | The most common kind — used for normal posts, messages, thoughts, etc. ||
2
| Recommend Relay | Users can publish events recommending relays. Helps clients discover relays to connect to. ||
3
| Contacts (Following List) | Stores a user’s list of followedpubkeys
. Often used by clients to display “follows”. ||
7
| Reaction | Like a “like” or emoji reaction to another event. ||
40
| Channel Creation (for kind 41 chats) | Used to define a new channel (in Nostr chat/group systems). ||
10002
| Relay List Metadata | Lets users publish a list of relays they read/write to — often used for syncing with clients. |
2. Author Allowlist
Only events signed by my personal keys are allowed to be published:
`authorized_pubkeys = ["npub1yourpubkeyhere..."]
This ensures the relay won't be used by spammers or unknown clients. It's my private, write-only relay. Ofcourse People can read from it.
I have also added indexing support for my relay. This will help people to search posts on my relay.
---
🔑 Part 2: Generating Nostr Keys
I generated a fresh Nostr keypair from scratch and converted it into the npub
format using Bech32. I kept the nsec
safe and used the npub
to authorize writing to my relay.
You can generate keys using:
nostr-tools generate
or from Python, Rust, or a CLI like nostr-key
.
---
🐍 Part 3: Writing to the Relay (EGBot in Python)
To publish events to my relay, I wrote a small Python script I call EGBot. It:
Signs Nostr events using my private key
Posts them to my local relay via WebSocket or REST
Encapsulates post data like Reddit title, URL, etc.
This script acts as the backend for injecting custom content into my relay.
---
⚙️ Part 4: Automating Reddit → Nostr via n8n
To make the bot work on its own, I used [n8n](
https://n8n.io)
— a powerful open-source automation tool.
🔄 The Flow:
1. Schedule Trigger
Runs every 8 hours/ whenever ocean mining pool mints a block
2. RSS Feed Node
Fetches the latest posts from the Machine learning news subreddit.
SAT 2 USD price
Whenever ocean mining pool mints a block
Every morning, DeepLearning papers from arxiv
3. Filter Node
Filters out old posts or irrelevant ones using pub\_date vs current time.
4. Function/Code Node
Uses JavaScript to:
Strip HTML
Decode entities
Clean up titles/content
5. HTTP Request Node
Calls my REST API (Python bot) to trigger the post to my relay.
---
🔐 Why Only My Relay?
I’ve limited the bot to post only to my own self-hosted relay, because:
I want to avoid spamming the wider Nostr network
My relay acts as a personal content mirror/archive
It gives me full editorial and moderation control
This way, the content is preserved on Nostr, but without polluting public relays.
---
🔭 What’s Next?
I am experimenting with homomorphic encryption over Nostr. I will use this bot to do some experiments around it.
---
🧪 Live Bot
You can follow the bot on Nostr:
https://primal.net/p/nprofile1qqsgm93zkrqzxdkfcd3lwplapz9grwn0lwyt8gnxc8qnh2p9cwws7jqevrumf