-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[WIP] nixos/mautrix-telegram: init module #60151
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
Conversation
581185e
to
27ed81f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all thanks a lot for upstreaming NixOS modules for Matrix bridges!
Aside from the comments below I have another concern about this: both mautrix-whatsapp
and mautrix-telegram
are more or less equal to configure (well, except for the alembic
part here), so I'm still wondering if we can create a single module where you can deploy several bridges, similar to the approach taken for services.prometheus.exporters
where you can deploy multiple prometheus exporters using the same abstration in the NixOS module.
DynamicUser = true; | ||
StateDirectory = "mautrix-telegram"; | ||
ExecStart = '' | ||
${pkgs.mautrix-telegram}/bin/mautrix-telegram -c "${configFile}/config.yaml" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid that this won't work right away. As described in the upstream docs you need to configure a database first using alembic
.
To get this working locally, I had to patch the mautrix-telegram
package accordingly: #59519
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had an error locally to generate the database. I will try with your pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I try to merge your pull request but I've a problem during the generation of the database :
Traceback (most recent call last):
File "/nix/store/2z280p610w8yn9ypsngk2xzpgi54hl6b-python3.7-alembic-1.0.7/bin/.alembic-wrapped", line 11, in <module>
sys.exit(main())
File "/nix/store/2z280p610w8yn9ypsngk2xzpgi54hl6b-python3.7-alembic-1.0.7/lib/python3.7/site-packages/alembic/config.py", line 527, in main
CommandLine(prog=prog).main(argv=argv)
File "/nix/store/2z280p610w8yn9ypsngk2xzpgi54hl6b-python3.7-alembic-1.0.7/lib/python3.7/site-packages/alembic/config.py", line 521, in main
self.run_cmd(cfg, options)
File "/nix/store/2z280p610w8yn9ypsngk2xzpgi54hl6b-python3.7-alembic-1.0.7/lib/python3.7/site-packages/alembic/config.py", line 501, in run_cmd
**dict((k, getattr(options, k, None)) for k in kwarg)
File "/nix/store/2z280p610w8yn9ypsngk2xzpgi54hl6b-python3.7-alembic-1.0.7/lib/python3.7/site-packages/alembic/command.py", line 276, in upgrade
script.run_env()
File "/nix/store/2z280p610w8yn9ypsngk2xzpgi54hl6b-python3.7-alembic-1.0.7/lib/python3.7/site-packages/alembic/script/base.py", line 475, in run_env
util.load_python_file(self.dir, "env.py")
File "/nix/store/2z280p610w8yn9ypsngk2xzpgi54hl6b-python3.7-alembic-1.0.7/lib/python3.7/site-packages/alembic/util/pyfiles.py", line 90, in load_python_file
module = load_module_py(module_id, path)
File "/nix/store/2z280p610w8yn9ypsngk2xzpgi54hl6b-python3.7-alembic-1.0.7/lib/python3.7/site-packages/alembic/util/compat.py", line 156, in load_module_py
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "alembic/env.py", line 10, in <module>
from mautrix_telegram.base import Base
ModuleNotFoundError: No module named 'mautrix_telegram.base'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you used mautrix-telegram.alembic
or python3Packages.alembic
? As described in the PR you need a alembic
with mautrix-telegram
available which is why I added the passthru
expression.
I just checked it locally whether it creates a sqlite db successfully in my mautrix-telegram
checkout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I merged just your commit on my branch and use a nix-shell to generated it so I think it should be the right packet, isn't ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unfortunately not documented in the bridge's wiki since this is usually not a problem when setting up the bridge in a git checkout of mautrix-telegram
.
I simply did a ln -sf ${pkgs.mautrix-telegram}/alembic alembic
with in a preStart
hook of the systemd
service back then. Unless you have any better ideas that should be the way to go :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried your suggestion Ma27 but I've this error :
ln: failed to create symbolic link 'alembic': Read-only file system
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please share your local diff with me then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pacien wrote:
Have you tried setting the working directory to the application's source root? It might work as
script_location
is defined relatively in alembic.ini.
Repeating myself here. The following works:
preStart = ''
cd ${pkgs.mautrix-telegram}
${pkgs.mautrix-telegram.alembic}/bin/alembic -x config=${configFile}/config.yaml upgrade head
'';
Also note that preStart
should belong to systemd.services.mautrix-telegram
instead of being nested in serviceConfig
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I've just seen the last answer while reading unread GitHub notifications. In fact that's even better than my solution 👍
So should I delete all my previous PR and retry in just one ? |
27ed81f
to
9cb1f05
Compare
No, I'm not even sure if we actually want to do that. Let's focus on getting |
enable = mkEnableOption "Mautrix-telegram, a bridge between Matrix and Telegram"; | ||
|
||
configOptions = mkOption { | ||
type = types.attrs; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(feel free to ignore) Another candidate for NixOS/rfcs#42
It would be nice to have a way to supply secret API keys and tokens ( |
IIRC this is not possible. You have a single config file for everything and we'd have to patch the bridge accordingly. This is more or less the same problem as in the corresponding |
@Ma27 wrote:
Just submitted a pull request to upstream for that: mautrix/telegram#332 |
DynamicUser = true; | ||
StateDirectory = "mautrix-telegram"; | ||
ExecStart = '' | ||
${pkgs.mautrix-telegram}/bin/mautrix-telegram -c "${configFile}/config.yaml" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pacien wrote:
Have you tried setting the working directory to the application's source root? It might work as
script_location
is defined relatively in alembic.ini.
Repeating myself here. The following works:
preStart = ''
cd ${pkgs.mautrix-telegram}
${pkgs.mautrix-telegram.alembic}/bin/alembic -x config=${configFile}/config.yaml upgrade head
'';
Also note that preStart
should belong to systemd.services.mautrix-telegram
instead of being nested in serviceConfig
.
options.services.mautrix-telegram = { | ||
enable = mkEnableOption "Mautrix-telegram, a bridge between Matrix and Telegram"; | ||
|
||
configOptions = mkOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An example and a default value would be nice here.
In particular, we could set appservice.database
to sqlite:////var/lib/mautrix-telegram/mautrix-telegram.db
by default to use an SQLite database placed in the StateDirectory of the service.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do that but the exemple will be long !
|
||
services.matrix-synapse.app_service_config_files = [ "${configFile}/registration.yaml" ]; | ||
|
||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you intend to maintain this module, you can set meta.maintainers
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never view a module with a maintainers ... OK I'll do it
mautrix/telegram#332 has been merged in upstream. |
Motivation for this change
On the same pattern that mautrix-whatsapp, I suggest this service for mautrix-telegram.
What do you think about it @Ma27 :-) ?
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nix-review --run "nix-review wip"
./result/bin/
)nix path-info -S
before and after)