little pi server

after getting fed up with spotify and learning about navidrome i decided to repurpose an raspberry pi 3 i had kicking around into a little linux server.[^1] it was nice to follow the well worn path of setting this up since it’s such a common thing to do.

my setup is basically a run-of-the-mill 2TB external usb drive, formatted with zfs, plugged into the pi, and i back this up with restic periodically. i would like to get a second drive and figure out how to get a bit of redundancy using zfs’ mirroring feature for when one of the drives inevitably eats shit.

as for software, i installed docker, plonked in my docker-compose.yaml for navidrome, sudo docker compose up -d and things were running! docker always felt annoying for development but it’s such a treat for running stuff in a server like this.

at this point, i can access navidrome on my local network, but not when i’m out of the house. to support that i wanted to connect to it via wireguard by way of tailscale. this is a lot more appealing to me than putting it on the internet, where it’s a lot more likely to be accessed by someone who’s not me. anyway tailscale setup on a single machine like this is very easy.

tailscale’s magic dns stuff lets me connect to the machine, i.e. connecting to something like peterspi:4533. but instead i wanted to connect to something more readable like music.schpet.com so i plonked in an A record into my dns, pointed it at the tailscale IP for the machine, and then voila, you can connect to the machine. you still need the port number though. so i setup caddy to reverse proxy that host to navidrome and we were good. and for fun, i setup caddy with my dns provider to do the lets encrypt dns challenge and get my services through https.

anyway running other people’s software is good and all but i learned that the pi in raspberry pi is for python, and the whole point of it is to promote running your own software. so, i like listening to shows on xray.fm and i know their website lets you play archives, so i thought it would be cool if i could get those into my music library automatically. and instead of stringing together some bash scripts, i thought i would write in rust instead and learn something given its new to me.

the download script came together quickly. clap is awesome for putting together CLIs. i really like how cargo kind of does it all (building! running! dependencies! docs! tests!) and you don’t really need to really figure out much outside of that. writing rust is hard, lots of ampersands to please this “borrow checker” and i don’t really have a strong idea of what’s going on there but that didn’t stop my program from doing the thing. was easy to figure out how parse webpages and add ID3 tags to mp3s.

the only real hangup came when it came to running this code on the pi. i first try rsync’ing my code over to it and compiling, but i had previously setup a watchdog to reboot the thing if it seemed like it had crashed or got stuck so cargo build just ended up being a slow way to reboot the pi. so next attempt: cross compile on the mac. this took a while to figure out, but i ended up using cross and running cross build --release --target=armv7-unknown-linux-musleabihf and 4 hours later after i was asleep a working binary popped out! anyway, i would love to figure out a less slow way to do this.

anyway, this has all been very fun and i hope to run more software on my tiny computer.

[^1]: well originally i put this on fly.io but using their volumes and vms would have cost a bunch of money

© 2024 peter schilling