5.5 KiB
+++ title = "Spacebar and a Translation Service" date = 2025-06-09 +++
Since Yesterday
- Polish up the blog a little bit
- Get a translation api set up
- Get a chat client set up
Spacebar Server
The Spacebar server is super easy to run on Nix - its flake just works! Below I write the relevant portions of my Nix config.
# flake.nix { # import server from the flake.nix on gh inputs.spacebar-server.url = "github:spacebarchat/server"; outputs = { spacebar-server, ... }: { nixosConfigurations."server" = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; specialArgs = { # pass spacebar-server to any module that wants it inherit spacebar-server; }; modules = [ # add spacebar to configuration ./services/spacebar.nix ]; }; }; }
# services/spacebar.nix { spacebar-server, lib, pkgs, ... }: { systemd.services.spacebar-server = { serviceConfig = { Type = "simple"; ExecStart = "${lib.getExe spacebar-server.packages.x86_64-linux.default}"; # Ensure the server is run by a non-priveleged user for security RemainAfterExit = true; User = "spacebar"; Group = "spacebar"; }; environment = { # Specify location of uploaded files and the db DATABASE = "/var/lib/spacebar-server/database.db"; STORAGE_LOCATION = "/var/lib/spacebar-server/files/"; }; }; # Create user that runs the server users.users.spacebar = { isSystemUser = true; group = "spacebar"; # Create home, where database.db and files/ are located home = "/var/lib/spacebar-server"; createHome = true; # utility packages while SSHing into the user packages = [ pkgs.git # package to test drive the server with the unpriveleged user spacebar-server.packages.x86_64-linux.default # edit the database pkgs.sqlite ]; # I have noshell in my flake, so there won't be a login shell unless it's specified shell = pkgs.bash; }; # Groups need to be 'initialized' on nixos users.groups.spacebar = {}; }
This configuration runs great! Well, given that you configure the database correctly - sqlite is going to be the death of me! api_endpointPublic
, cdn_endpointPublic
, and gateway_endpointPublic
all need to be set before the server's connected up properly to take new users. That means running the below series of commands from the sqlite3
repl - an interface without backspace~
# as spacebar user sqlite3 ~/database.db
update config set value='"https://spacebar-api.mtgmonkey.net/api/v9"' where key='api_endpointPublic'; update config set value='"https://spacebar-api.mtgmonkey.net"' where key='cdn_endpointPublic'; update config set value='"wss://spacebar-api.mtgmonkey.net"' where key='gateway_endpointPublic'; .exit
Beleive it or not, the server was only the easy part! I next had to configure the client.
There are generally 3 web clients to choose from when it comes to Spacebar.
- The official client, written in React, is the most beautiful. It's not fully featured, however, missing the home page, friends, DMs, and more.
- The legacy client, written in Typescript, is known to work. Unfortunately, it is quite outdated and, no matter how much I tried, I could not get it to build on Nix.
- JankClient, an unofficial client written in TypeScript, is, as its name suggests, quite janky. It requires frequent browser refreshes to fix visual glitches and is poorly optimised on mobile.
JankClient, despite its glitchiness, is the one I finally decided on. Though the official client has a flake, it's currently non-functional, and has been for a while. Neither of the other two have flakes, unfortunately, but it's easy enough to run JankClient with Docker. I first ran nix-shell -p compose2nix
before renaming compose.yaml
to docker-compose.yaml
(as compose2nix requires). I then ran compose2nix and used the output as the basis for services/spacebar.nix. I made a couple of major modifications: Firstly, I bound it to a different port as a matter of personal preference. I also changed all instances of podman
with docker
, as my rgit instance runs on docker and nix can only have 1 declaration of virtualisation.oci-containers.backend
. Secondly, the generated docker-build-spaceclient-jank.service
wouldn't run properly, so I had to build the image manually. Finally, I added an anubis PoW captcha and a reverse client entry in my ferron webserver, as appropriate.
All code above is, clearly, just simplified snippets; the actual file are linked below