{
"$type": "com.whtwnd.blog.entry",
"theme": "github-light",
"title": "Setting up a PDS on RISC-V",
"content": "# Setting up a PDS on RISC-V\n\nThis is a RISC-V endeavor, if you know what I mean :)\n\nBecause the Docker image doesn't support RISC-V, we'll need to do this Docker-less. This guide only covers the PDS itself; for the reverse proxy, I recommend [@benharri.org](https://bsky.app/profile/did:plc:v7tbr6qxk6xanxzn6hjmbk7o)'s [guide](https://benharri.org/bluesky-pds-without-docker/) as that's what I used and it works very well.\n\n> This guide assumes at least some familiarity with the Linux command line and some basic problem solving skills. It doesn't require knowledge of Node.js (lol)\n\n> If you don't have a RISC-V machine, you can still follow along by setting up a RISC-V Ubuntu Server 24.04 VM with [this guide](https://wiki.ubuntu.com/RISC-V/QEMU). Be aware however that the PDS won't be able to connect to the Bluesky network (unless you know QEMU networking).\n\n### Setup\n\nI'm using a StarFive VisionFive 2, equipped with 4GB of RAM and a 1TB NVMe SSD loaded with Ubuntu Server 24.04. If you actually want to use this as a PDS, you shouldn't run it off a microSD Card unless you don't care about your data or identity.\n\n### Disclaimer\n\nI have no idea what I'm doing when it comes to Node.js. I'm just doing what I think is right given the less-than-ideal circumstances, which it probably isn't.\n\nAdditionally, this guide assumes you're using Ubuntu 24.04. If you're using a different distro or version of Ubuntu, you'll need to adapt these instructions.\n\n## Set up Node.js\n\nNode.js is not available for RISC-V officially, so we need to use an unofficial build. I used v20.18.1, which is the newest 20.x version as of writing (the Bluesky PDS Docker image uses v20.11.0)\n\nFor the sake of simplicity, we're going to install to /usr/local so we don't have to mess with our path.\n\nDownload and install Node.js: `curl -L https://unofficial-builds.nodejs.org/download/release/v20.18.1/node-v20.18.1-linux-riscv64.tar.gz | sudo tar -xz -C /usr/local --strip-components=1`\n\nNow try to run `node`. In my case I needed to install `libatomic1` first: `sudo apt install libatomic1`\n\nIt worked if you get a prompt. Type `.exit` to leave.\n\n## PDS Setup, Part One\n\nI already had `git` installed but you will need to install it if you don't have it: `sudo apt install git`\n\n`git clone` the PDS repository: `git clone https://github.com/bluesky-social/pds`\n\nThis needs `pnpm` so we will need to install it: `npm install -g pnpm@latest`\n\nA few dependencies require building from source. I wouldn't recommend installing build tools on a server (makes it less secure) but in this case we have no choice: `sudo apt install build-essential` You can always remove the build tools later.\n\n> If you're getting errors about the lockfile you may need to install an earlier version of pnpm with something like: `npm install -g pnpm@latest-9`\n\nThe fun part, pulling in the dependencies: `pnpm install --production --frozen-lockfile`\n\nAs we're compiling from source, this will take some time (10 minutes on the VisionFive 2), so sit back and relax, maybe get yourself some coffee (or in Metric units, tea)\n\n## libvips and sharp\n\nIf you try to run the PDS as is, it will fail because sharp is missing libvips. You see, there is no RISC-V libvips binary, nor does it try to compile one. Now Ubuntu 24.04 ships with its own libvips, but it's too old (8.15.1 when we need at least 8.15.3). Therefore we have to build libvips from source, and then build sharp from source so it'll use it.\n\n### build libvips\n\nlibvips has many dependencies for building, and the easiest way to get them (on Ubuntu 24.04) is to install `libvips-dev` to pull in the dependencies and then remove `libvips` (called `libvips42t64` on Ubuntu 24.04). Make sure you don't run `sudo apt autoremove` before you're done building or you'll have to do it again. And double check to make sure the native `libvips` package isn't installed or vips will report as 8.15.1.\n\n> The official build instructions for libvips are [here](https://www.libvips.org/install.html#building-libvips-from-source).\n\nCompling libvips is easy enough so I won't go over it here; just follow the official build instructions. Set the prefix to `/usr/local` as we will be using it on this machine.\n\n### build sharp\n\n> The version of sharp you build must match what the PDS is using.\n\nCreate a new folder somewhere and run `npm install --save node-addon-api node-gyp` to install build dependencies. Now run `SHARP_FORCE_GLOBAL_LIBVIPS=1 npm install --build-from-source sharp`. For some reason it didn't work with just the `--build-from-source` flag, but the environment variable worked for me.\n\nAfter it's done, check for the existence of the node_modules/sharp/src/build/Release folder, there should be a binary in there. If there isn't, something probably failed or it didn't actually compile.\n\n### Getting sharp working\n\nWe're going to copy the sharp we just built to where the PDS expects it. There's probably a better way to do this, but this seems to work fine. Double check the sharp versions match.\n\n\n```sh\ncp -r /sharp-build-path/node_modules/sharp/src/build /pds-path/service/node_modules/.pnpm/sharp@0.33.5/node_modules/sharp/src\n```\n\n## Actual PDS configuration\n\nFor here on, you can just follow @benharri.org's [guide](https://benharri.org/bluesky-pds-without-docker/#config). However, I recommend you add `PDS_BLOB_UPLOAD_LIMIT=52428800` to your env file, otherwise you may experience issues with video and other blob uploads.\n\n## Updating\nUnsupported configurations like this might break with updates, so express caution when doing so. Things are certain to break if sharp is updated though. To fix sharp you will need to build the newer version of sharp that the PDS requires. You may also need to build a newer version of `libvips` if it depends on it.\n\n## Closing remarks\n- [I performed some testing](https://bsky.app/profile/riscvpdstest.akizuki.best), and while everything appears to work fine, given how we're in several layers of \"not officially supported\", I wouldn't recommend this for production use.\n- I'd like to see official RISC-V support in sharp. Having to build `libvips` and sharp from source is a major hurdle that shouldn't be there.\n- Following that, I'd also like to see official RISC-V support from Node.js. I'm sure this will happen eventually though.",
"createdAt": "2025-05-20T19:45:22.267Z",
"visibility": "url"
}