NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.06k stars 13.39k forks source link

pleroma: `pleroma_ctl instance gen` fails due to missing COOKIE file #170805

Open lambdadog opened 2 years ago

lambdadog commented 2 years ago

Describe the bug

Pleroma fails to run due to missing cookie file. This causes no issues with the NixOS module as it overloads the pleroma derivation's cookieFile argument, but renders the default build unusable without explicitly setting RELEASE_COOKIE.

This is an issue due to pleroma_ctl instance gen, the intended way to generate a config for a fresh instance, calling into pleroma in order to run. It's worth noting using pleroma_ctl instance gen is the intended way to generate a config for the NixOS module and set up the postgresql database as per the NixOS docs for the module.

Steps To Reproduce

On nixpkgs master:

$ nix-shell -p pleroma
$ cd $(mktemp -d)
$ pleroma_ctl instance gen --output config.exs --output-psql setup.psql
cat: /nix/store/lxxn1n18k959n8l41fizbi6gqz515xf4-pleroma-2.4.2/releases/COOKIE: No such file or directory

Expected behavior

pleroma_ctl running and generating the config.exs and setup.psql files.

Notify maintainers

@petabyteboy @ninjatrappeur @yu-re-ka @kloenk

Metadata

[lambdadog@taiga:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.15.33, NixOS, 22.05 (Quokka), 22.05pre368735.33772708c6d`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.8.0pre20220322_d5d4d98`
 - channels(lambdadog): `"nixpkgs-unstable"`
 - channels(root): `"musnix, nixos"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

I did however explicitly use nixpkgs master for testing this, as so:

[lambdadog@taiga:~]$ nix repl
Welcome to Nix 2.8.0pre20220322_d5d4d98. Type :? for help.

nix-repl> nixpkgs-pleroma = (fetchTarball https://github.com/NixOS/nixpkgs/archive/master.tar.gz)

nix-repl> pkgs-pleroma = import nixpkgs-pleroma {}                                                

nix-repl> :u pkgs-pleroma.pleroma                                                                 
warning: error: plugin-files set after plugins were loaded, you may need to move the flag before the subcommand

[nix-shell:~]$ cd $(mktemp -d)

[nix-shell:/run/user/1000/tmp.ZejW0ys6w5]$ pleroma_ctl instance gen --output config.exs --output-psql setup.psql
cat: /nix/store/lxxn1n18k959n8l41fizbi6gqz515xf4-pleroma-2.4.2/releases/COOKIE: No such file or directory
lambdadog commented 2 years ago

Obviously the easiest solution for this is to simply generate a cookie by default for interactive use on first run, but I'm unsure if this behavior would be undesireable for anyone's real-world use-case.

Instinctively I want to say it would be fine, though.

lambdadog commented 2 years ago

Somewhat unrelated, but https://github.com/NixOS/nixpkgs/blob/4ee88025c2e84139b42d44e9e1c1746c0e0e538d/pkgs/servers/pleroma/default.nix#L22-L25 is false.

You just have to use wrapProgram's --run flag rather than --set. You can run arbitrary commands, including setting an environmental variable with export.

ex. (from a since deprecated hack I wrote to load my emacs config from nix)

  makeWrapper "$prog" "$out/bin/$progname" \
    --run 'test -a "$HOME/.emacs" && echo "~/.emacs exists, failing to load config." && exit 1' \
    --run 'test -d "$HOME/.emacs.d" && echo "~/.emacs.d exists, failing to load config." && exit 1' \
    --run 'export NIX_STORED_XDG_CONFIG_HOME=$XDG_CONFIG_HOME' \
    --run 'export EMACSNATIVELOADPATH="$EMACSNATIVELOADPATH:$HOME/.local/share/emacs/eln-cache/"' \
    --set XDG_CONFIG_HOME '${xdg-config-home}' \
    --set NIX_EMACS_INIT_PACKAGE '${configPkg.pname}'
picnoir commented 2 years ago

Related: https://github.com/NixOS/nixpkgs/issues/166229

lambdadog commented 2 years ago

Ah, I didn't notice that issue, ty!

inexcode commented 2 years ago

Not only pleroma_ctl fails. If configs are provided manually, pleroma fails to start. The only line in log is about that cookie.

On NixOS 21.11 pleroma didn't crash, and pleroma_ctl instance gen worked too. But it also had the line about cookie. Maybe it fails not because of cookie file?

lambdadog commented 2 years ago

@inexcode If you wish to run a pleroma instance you can run it using the NixOS service, which overloads the cookieFile, but you're correct in that the server fails to start too with RELEASE_COOKIE unset.

If you desperately need to run for testing purposes, you should be able to set RELEASE_COOKIE to a file in the command-line.

ex.

$ dd if=/dev/urandom bs=1 count=16 | hexdump -e '16/1 "%02x"' > /path/to/your/release/cookie
$ RELEASE_COOKIE=/path/to/your/release/cookie pleroma
Elinvention commented 1 year ago

I struggled to run database maintenance tasks like pleroma_ctl database prune_objects, but I finally found a way to run them: sudo -u pleroma env RELEASE_COOKIE=/var/lib/pleroma/.cookie pleroma_ctl database prune_objects. Thanks @lambdadog for pointing me in the right direction.

wolfsprite commented 1 year ago

I am unable to start the NixOS pleroma module while its config is missing: error: The option 'services.pleroma.configs' is used but not defined.

and the description in the configs option for the pleroma module sent me to the Pleroma section of the NixOS manual: Have a look to Pleroma section in the NixOS manual for more informations.

However, the first instruction there resulted in the failing to generate due to missing COOKIE error: pleroma_ctl instance gen --output config.exs --output-psql setup.psql cat: /nix/store/4hwmq96g9qb2dbvmfssnvppsafjwnx2x-pleroma-2.4.3/releases/COOKIE: No such file or directory

so I'm a little lost on how to get the module running in the first place if I'm unable to generate the necessary configs for it, and I ended up here while searching duckduckgo for the no such COOKIE message.

lambdadog commented 1 year ago

This should work as a workaround for the time being @wolfsprite.

$ dd if=/dev/urandom bs=1 count=16 | hexdump -e '16/1 "%02x"' > /tmp/pleroma-cookie
$ export RELEASE_COOKIE=/tmp/pleroma-cookie

then you should be able to run any pleroma_ctl commands needed freely, at least in that terminal window.

wolfsprite commented 1 year ago

That worked! Thanks for the assistance there. :3


edit: I did also have to manually make the /var/lib/pleroma/static folder for pleroma_ctl to write robots.txt into, otherwise the whole generation was failing.

Do you want to deduplicate uploaded files? (y/n) [n] y
** (File.Error) could not make directory (with -p) "/var/lib/pleroma/static": no such file or directory
    (elixir 1.13.4) lib/file.ex:316: File.mkdir_p!/1
    (elixir 1.13.4) lib/enum.ex:1593: Enum."-map/2-lists^map/1-0-"/2
    (pleroma 2.4.3) lib/mix/tasks/pleroma/instance.ex:250: Mix.Tasks.Pleroma.Instance.run/1
    (stdlib 3.17) erl_eval.erl:685: :erl_eval.do_apply/6
    (elixir 1.13.4) lib/code.ex:404: Code.validated_eval_string/3

For anyone else that may encounter this: just make sure that the directory you tell pleroma_ctl gen to use for static files actually exists first. I thought I was safe using the default. >.>;