Anyone with experience using NixOS to create a Lemmy instance, please share any caveats and troubleshooting tips you have.
Oh hello, my instance is on NixOS!
There’s a NixOS module for lemmy, but it’s kind of broken right now and in the middle of a PR. If you want, you can replace the current nix package with the one from the fork, and successfully deploy it, however, if I were you, I’d just wait a week or so.The configuration right now requires a bunch of hacks, and even doing some non-reproducible stuff.
That PR link returns a 404.
This is my way of learning Nix/NixOS so I’d rather give it a go before the PR is merged.
Sorry, missed a character, try again
I’m so deep in the weeds. I don’t know what questions to ask.
Okay, I’ve actually figured simplifying it out, it’s not that bad. Let me share my config:
First, since the PR isn’t in
nixos-unstable
yet, I’m adding the fork as a flake inputinputs = { nixpkgs-lemmy.url = "github:CobaltCause/nixpkgs/lemmy-module-improvements"; };
then, in my system configuration, I add this:
# Not sure if this is required, maybe caddy auto-allows it networking.firewall.interfaces.eth0.allowedTCPPorts = [443 80]; # Override the lemmy module with the one from the PR disabledModules = ["services/web-apps/lemmy.nix"]; imports = [ "${inputs.nixpkgs-lemmy}/nixos/modules/services/web-apps/lemmy.nix" ]; services.lemmy = { database.createLocally = true; database.uri = "postgres:///lemmy?host=/run/postgresql&user=lemmy"; enable = true; settings = { hostname = "<YOUR_HOSTNAME>"; }; caddy.enable = true; };
and, that’s it!
However, I’m not sure if it will cleanly deploy, as you might get an error while starting.
If so, please check postgresql logssudo journalctl -fu postgresql
. The error will most likely be something like this:
[…]["RI_ConstraintTrigger_a_16639" is a system trigger
[…] ] ERROR: permission denied:If that happens, you need to manually run the migration until the fix is merged into Lemmy. Here’s how I did it:
sudo su - postgres
psql -v ON_ERROR_STOP=1 lemmy postgres
- (in psql)
SET ROLE lemmy;
- Paste the SQL code from here: https://github.com/LemmyNet/lemmy/issues/2784#issuecomment-1578337686
After that’s done, you can exit the postgres CLI by typing
\q
, exit the postgres user and just simplysudo systemctl restart lemmy
which should start properly now, and be accessible to the outside network.
Open it and it will give you the initial setup screen. Good luck!
FWIW, I’m running NixOS but gave up on running the Lemmy module. I gave up when I realized that Lemmy seems to need superuser access to the Postgresql server, to install plugins or whatever.
So instead, I used Arion to make a docker-compose image, running in podman. Works great so far.
Thanks for sharing your experience.
I have not read the full docs on setting up lemmy yet. But i don’t think it matters what distro you use as long as the distro can run docker. So setup docker and from their it is the same for any distro.
NixOS has native support for Lemmy, Docker/OCI containers are not needed.
That is cool. I did not know this. Still i think docker would be the most universal and simple way.
If someone is using NixOS, they would prefer native support. It’s easier to set up than Docker and fully integrated with the rest of their system’s configuration. Though NixOS also supports declaring OCI containers (with Docker or Podman) if needed.
do you have working config or flake available? im on latest unstable channel and it builds and installs fine but when trying to login or setup admin account i receive an error
syntaxerror: unexpected end of json input
which when traced in browser console it seems to do with captcha endpoint downgrade through reverse proxy. i use traefik so will have to investigate further