Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lambdadog opened this issue Apr 28, 2022 · 10 comments
Open

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

lambdadog opened this issue Apr 28, 2022 · 10 comments
Labels
0.kind: bug 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: nixos

Comments

@lambdadog
Copy link
Contributor

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
Copy link
Contributor Author

lambdadog commented Apr 28, 2022

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
Copy link
Contributor Author

lambdadog commented Apr 28, 2022

Somewhat unrelated, but

# There's no way to use a subprocess to cat the content of the
# file cookie using wrapProgram: it gets escaped (by design) with
# a pair of backticks :(
# We have to come up with our own custom wrapper to do this.
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
Copy link
Member

picnoir commented Apr 28, 2022

Related: #166229

@lambdadog
Copy link
Contributor Author

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

@inexcode
Copy link

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
Copy link
Contributor Author

@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
Copy link
Contributor

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.

RobotDisco added a commit to RobotDisco/nix-config that referenced this issue Dec 14, 2022
(we're doing this because running ~nix-shell -p pleroma-otp~ and
running the commands the nixos manual said don't work and people claim
it's fine if you run the commands as part of the service.)

https://nixos.org/manual/nixos/stable/index.html#module-services-pleroma-generate-config

NixOS/nixpkgs#170805
RobotDisco added a commit to RobotDisco/nix-config that referenced this issue Dec 17, 2022
(we're doing this because running ~nix-shell -p pleroma-otp~ and
running the commands the nixos manual said don't work and people claim
it's fine if you run the commands as part of the service.)

https://nixos.org/manual/nixos/stable/index.html#module-services-pleroma-generate-config

NixOS/nixpkgs#170805
@wolfsprite
Copy link

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
Copy link
Contributor Author

lambdadog commented Dec 18, 2022

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
Copy link

wolfsprite commented Dec 19, 2022

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. >.>;

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: nixos
Projects
None yet
Development

No branches or pull requests

6 participants