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

weblate: init at 4.13.1, add module #169797

Closed
wants to merge 17 commits into from
Closed

Conversation

erictapen
Copy link
Member

Description of changes

Back in the Summer of Nix 2021 I created a Flake for Weblate: https://github.com/ngi-nix/weblate

Now I want to merge this into Nixpkgs in order to increase discoverability and likelihood of maintenance (even though I kept the flake uptodate since the summer and also plan to do so in the future.

Older attempt: #48726

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 22.05 Release Notes (or backporting 21.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@erictapen erictapen requested a review from jtojnar April 22, 2022 14:03
@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Apr 22, 2022
@erictapen
Copy link
Member Author

Hi @wiredhikari, thanks for your review. Could you add a bit on what exactly you checked about the code? Did you just look at it or did you also run the tests, try the installation?

Answering that might help other people to determine wether this is mergeable.

@wiredhikari
Copy link

I went through the code and tests, seemed fine to me

@erictapen erictapen changed the title weblate: init at 4.12, add module weblate: init at 4.13.1, add module Aug 3, 2022
@erictapen erictapen added the 8.has: module (new) This PR adds a module in `nixos/` label Aug 3, 2022
Copy link
Member

@RaitoBezarius RaitoBezarius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I do something to help you move this PR forward?

environment = {
PYTHONPATH = "${settings_py}";
DJANGO_SETTINGS_MODULE = "settings";
GI_TYPELIB_PATH = "${pkgs.pango.out}/lib/girepository-1.0:${pkgs.harfbuzz}/lib/girepository-1.0";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makeLibPath [ pkgs.pango pkgs.harfbuzz ]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lib.makeLibraryPath [ pkgs.pango pkgs.harfbuzz ] produces /nix/store/a83690v9dsx2l2bafc1bqs17nsa8x4i8-pango-1.50.8/lib:/nix/store/jr685bs5jjs3rb9r297hma145wc5jbsn-harfbuzz-5.1.0/lib, but I think we need the girepository-1.0 bit to be included.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be ideally done by wrapper (e.g. gobject-introspection + wrapGAppsNoGuiHook) in the package itself so that it works outside the context of the module: https://nixos.org/manual/nixpkgs/stable/#ssec-gnome-typelibs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right @erictapen

Copy link
Member Author

@erictapen erictapen Sep 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently trying to move the the gobject-introspection and PATH logic into the package, but I'm having a hard time properly doing that inside mkPoetryApplication and buildPythonApplication. Will try some more and report back.

But note that we can't completely remove the wrapping, as the settings.py is generated in the module. So the package itself will probably never be of much use outside the module.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's a Django app, we can still rewire DJANGO_SETTINGS_MODULE to something else (I have already done it multiple times)


locations = {
"= /favicon.ico".alias = "${pkgs.weblate}/lib/${pkgs.python3.libPrefix}/site-packages/weblate/static/favicon.ico";
"/static/".alias = "${pkgs.weblate}/lib/${pkgs.python3.libPrefix}/site-packages/weblate/static/";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think static should be refactored in the module system and let the default be the path you're using.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand your proposition? The / route must already be served by the uwsgi unix domain socket, so it's necessary to explicitly route only /static/.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erictapen

I meant it would be nice to have pkgs.weblate.static which references to ${pkgs.weblate}/lib/${pkgs.python3.libPrefix}/site-packages/weblate/static/ and have in the module system cfg.staticPackage which points to pkgs.weblate.static and here you would reference ${cfg.staticPackage}/favicon.ico for example.

So (1) someone can access to the static part of Weblate (here, it means to build the weblate derivation, so few benefits) (2) someone can replace the static part of Weblate with a patch or something easily.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I get what you are aiming at, but I don't see the benefits yet.

Is this pattern used anywhere else in Nixpkgs you could point me to?

Is there any existing replacement for the static part of Weblate? I don't see the use case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A rapid grep shows at least:

pkgs/servers/misc/navidrome/default.nix
26:  ui = callPackage ./ui {

pkgs/servers/gotify/default.nix
34:  ui = callPackage ./ui.nix { };

I imagine those are more involved, as they are most likely Node-generated static files.
Maybe static is not a good name as it could get confused with a statically-linked binary from what I see in nixpkgs, but ui is often used.

Is there any existing replacement for the static part of Weblate? I don't see the use case.

There may be situations where you want to do pkgs.runCommand "patch-static" ''cp -r ${pkgs.weblate.static} $out && do something with $out to patch it, e.g. a robots.txt, etc. and pass it to cfg.staticPackage rather than patching the whole pkgs.weblate.

I have no strong feeling on this, it can be added later on if anyone has a real need for it, but most of the time, I see that people would appreciate having override options rather than locking them into a let expression ; in this case, overlaying the original weblate package would do the job as long as it is a reasonable patch.

@erictapen
Copy link
Member Author

Can I do something to help you move this PR forward?

There are no open issues from my side with this one, so reviewing it helps definetly! Thanks.

nixos/modules/services/web-apps/weblate.nix Outdated Show resolved Hide resolved
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"HOST": "/run/postgresql",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can use sockets here as well so that we do not need user and password.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, sockets are used here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the unix socket is already used. I removed the PASSWORD and PORT option to not cause any confusion.

environment = {
PYTHONPATH = "${settings_py}";
DJANGO_SETTINGS_MODULE = "settings";
GI_TYPELIB_PATH = "${pkgs.pango.out}/lib/girepository-1.0:${pkgs.harfbuzz}/lib/girepository-1.0";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be ideally done by wrapper (e.g. gobject-introspection + wrapGAppsNoGuiHook) in the package itself so that it works outside the context of the module: https://nixos.org/manual/nixpkgs/stable/#ssec-gnome-typelibs

GI_TYPELIB_PATH = "${pkgs.pango.out}/lib/girepository-1.0:${pkgs.harfbuzz}/lib/girepository-1.0";
};
weblate-env = pkgs.writeShellScriptBin
"weblate-env"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, is this used anywhere other then tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to expose the django-admin stuff so that someone can do weblate-admin createsuperuser or whatever.

Copy link
Member Author

@erictapen erictapen Sep 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jtojnar Yeah you would use it whenever you have to run admin tasks, as I see no other way to put the correct settings.py into the PYTHONPATH.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make settings.py in the package load /etc/weblate/settings.py or something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be a nice thing in the future would be to have a "package with a setting", i.e. cfg.weblate.withSettings (...) and the settings would be baked into it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why would one want to run the package outside NixOS in the first place?
Upstreams intention seems to be, that you download the git repository on your server, run a few install scripts and then edit the settings.py by hand to your likings. Before you edit the file, their software isn't usable as well. I don't see why we should offer a way to use Weblate outside of a deployment framework, when upstream doesn't.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Precisely to be able to do admin tasks when needed, without having to use weird weblate-env runner. That is also a thing going out of way of upstream but a one much less convenient to use.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why would one want to run the package outside NixOS in the first place? Upstreams intention seems to be, that you download the git repository on your server, run a few install scripts and then edit the settings.py by hand to your likings. Before you edit the file, their software isn't usable as well. I don't see why we should offer a way to use Weblate outside of a deployment framework, when upstream doesn't.

As said, no strong feeling on this. It helps a lot to manage multi-instances, diagnose existing setups, etc.
It can be done in a later PR if anyone has a need for it.

((pkgs.lib.concatStrings (pkgs.lib.mapAttrsToList (n: v: "export ${n}=${v}\n") environment)) + ''
eval -- "\$@"
'');
weblatePath = with pkgs; [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this should be already on PATH, in the package.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User = "postgres";
Group = "postgres";
ExecStart = ''
${pkgs.postgresql}/bin/psql weblate -c "CREATE EXTENSION IF NOT EXISTS pg_trgm"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty invasive but not sure what else to do. According to https://www.postgresql.org/docs/current/pgtrgm.html, it might not be necessary to run it as postgres user.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is enough to add CREATE in ensurePermissions and run this under the weblate user.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Do note that it may provide access to the postgres user anyway because if someone can do arbitrary CREATE EXTENSION, they may be able to load their own ext and do bad stuff, the postgres solution is not that bad.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't look further into it, but if the situation is like the two of you described I'd rather execute known code once with higher privileges, than to give the weblate user more privileges for potentially malicious code?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think letting as-is, is better.

"postgresql.service"
];
environment = environment // {
CELERY_WORKER_RUNNING = "1";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this?

pkgs/servers/web-apps/weblate/default.nix Outdated Show resolved Hide resolved
Comment on lines +10 to +23
pyproject = ./pyproject.toml;
poetrylock = ./poetry.lock;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we upstream these?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never tried it, but I'd like to, yes. Could imagine upstream not to be very willing to change their build system / maintain a second one though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe open an issue explaining the needs for lock files first?

@erictapen
Copy link
Member Author

I just learned, that poetry2nix was dropped from Nixpkgs.
That would make it infeasible to add Weblate support to NixOS through this PR. I'd try to continue maintaining the Flake instead.

@erictapen erictapen closed this Nov 9, 2023
@erictapen erictapen mentioned this pull request Jul 8, 2024
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (new) This PR adds a module in `nixos/` 8.has: module (update) This PR changes an existing module in `nixos/` 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 1-10 10.rebuild-darwin: 1 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants