Created
February 6, 2025 10:45
-
-
Save 0xc1c4da/55514c4e377492324ddd44b3ecf65d52 to your computer and use it in GitHub Desktop.
Use Radicle.xyz with Tor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
description = "A flake that demonstrates Radicle.xyz with Tor "; | |
nixConfig = { | |
extra-substituters = [ | |
"https://nix-community.cachix.org" | |
]; | |
extra-trusted-public-keys = [ | |
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" | |
]; | |
}; | |
inputs = { | |
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | |
flake-utils.url = "github:numtide/flake-utils"; | |
}; | |
outputs = { self, nixpkgs, flake-utils, ... }: | |
flake-utils.lib.eachDefaultSystem (system: | |
let | |
inherit (nixpkgs) lib; | |
pkgs = import nixpkgs { | |
inherit system; | |
config = { | |
allowUnfree = true; | |
}; | |
}; | |
in | |
{ | |
devShells = { | |
default = pkgs.mkShell { | |
packages = with pkgs; [ | |
radicle-node | |
radicle-httpd | |
radicle-explorer | |
tor | |
jq | |
python3 | |
]; | |
env ={ | |
TOR_SOCKS_PORT = "9050"; | |
# TOR_CONTROL_PORT = "9051"; | |
TOR_HIDDEN_PORT = "8776"; | |
HTTP_PORT = "8000"; | |
}; | |
shellHook = '' | |
export RAD_HOME="$(git rev-parse --show-toplevel)/.radicle" | |
export TOR_HOME="$(git rev-parse --show-toplevel)/.tor" | |
# Create directory for hidden service if it doesn't exist | |
mkdir -p "$TOR_HOME/radicle" | |
chmod 700 "$TOR_HOME/radicle" | |
# Generate torrc configuration if it doesn't exist | |
if [ ! -f "$TOR_HOME/torrc" ]; then | |
cat > "$TOR_HOME/torrc" << EOF | |
HiddenServiceDir "$TOR_HOME/radicle" | |
HiddenServicePort $TOR_HIDDEN_PORT | |
SocksPort $TOR_SOCKS_PORT | |
EOF | |
fi | |
# Start tor in background | |
tor -f "$TOR_HOME/torrc" & | |
TOR_PID=$! | |
# Wait for the hidden service to be ready | |
while [ ! -f "$TOR_HOME/radicle/hostname" ]; do | |
sleep 1 | |
done | |
echo "Tor Hidden Service address:" | |
cat "$TOR_HOME/radicle/hostname" | |
# Check if config.json exists and has proxy/onion settings | |
if [ -f "$RAD_HOME/config.json" ]; then | |
# Get the onion hostname without port | |
ONION_HOST=$(cat "$TOR_HOME/radicle/hostname" | tr -d '\n') | |
# Check if proxy and onion settings already exist | |
if ! jq -e '.node.proxy and .node.onion' "$RAD_HOME/config.json" > /dev/null; then | |
# Settings don't exist, stop node and update config | |
rad node stop | |
jq '.node += { | |
"proxy": "127.0.0.1:'"$TOR_SOCKS_PORT"'", | |
"onion": { | |
"mode": "forward" | |
}, | |
"externalAddresses": [ | |
"'"$ONION_HOST"':'"$TOR_HIDDEN_PORT"'" | |
] | |
}' "$RAD_HOME/config.json" > "$RAD_HOME/config.json.tmp" && mv "$RAD_HOME/config.json.tmp" "$RAD_HOME/config.json" | |
# Start radicle node after config is updated | |
rad node start | |
fi | |
else | |
echo "Warning: Cannot start radicle node - config.json not found at $RAD_HOME/config.json" | |
fi | |
echo "Starting HTTP server for radicle-explorer at port $HTTP_PORT" | |
python3 -m http.server $HTTP_PORT -d ${pkgs.radicle-explorer} & | |
HTTP_PID=$! | |
# Cleanup on exit | |
trap "kill $TOR_PID $HTTP_PID" EXIT | |
''; | |
}; | |
}; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment