Skip to content

[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

Closed
wants to merge 2 commits into from

Conversation

Vskilet
Copy link
Contributor

@Vskilet Vskilet commented Apr 24, 2019

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
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Sorry, something went wrong.

@Vskilet Vskilet requested a review from infinisil as a code owner April 24, 2019 09:26
@ofborg ofborg 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 24, 2019
Copy link
Member

@Ma27 Ma27 left a 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"
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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'

Copy link
Member

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.

Copy link
Contributor Author

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 ?

Copy link
Member

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 :)

Copy link
Contributor Author

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

Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Member

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 👍

@Vskilet
Copy link
Contributor Author

Vskilet commented Apr 24, 2019

[...] if we can create a single module where you can deploy several bridges [...]

So should I delete all my previous PR and retry in just one ?
And I should add a default configuration if we do that, isn't it ?

@Ma27
Copy link
Member

Ma27 commented Apr 24, 2019

So should I delete all my previous PR and retry in just one ?

No, I'm not even sure if we actually want to do that. Let's focus on getting mautrix-whatsapp functional for now to have a POC in the nixpkgs master and discuss here if we want to unify the modules.

@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Apr 24, 2019
@Vskilet Vskilet changed the title nixos/mautrix-telegram: init module [WIP] nixos/mautrix-telegram: init module Apr 26, 2019
enable = mkEnableOption "Mautrix-telegram, a bridge between Matrix and Telegram";

configOptions = mkOption {
type = types.attrs;
Copy link
Member

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

@ofborg ofborg bot added 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux and removed 10.rebuild-linux: 1-10 labels May 28, 2019
@pacien
Copy link
Contributor

pacien commented Jun 5, 2019

It would be nice to have a way to supply secret API keys and tokens (telegram.api_id, telegram.api_hash and telegram.bot_token) outside of the world-readable nix store. This can be achieved by using an environment file if mautrix-telegram supports configuration overrides through environment variables.

@Ma27
Copy link
Member

Ma27 commented Jun 5, 2019

This can be achieved by using an environment file if mautrix-telegram supports configuration overrides through environment variables.

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 mautrix-whatsapp PR (#59211).

@pacien
Copy link
Contributor

pacien commented Jun 6, 2019

@Ma27 wrote:

IIRC this is not possible. You have a single config file for everything and we'd have to patch the bridge accordingly.

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

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

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.

Copy link
Contributor Author

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" ];

};
Copy link
Contributor

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.

Copy link
Contributor Author

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

@pacien
Copy link
Contributor

pacien commented Jun 7, 2019

mautrix/telegram#332 has been merged in upstream.

@Vskilet
Copy link
Contributor Author

Vskilet commented Jun 25, 2019

Ok guys, @pacien in #63589 suggest something better than this and it anticipates the next version of mautrix-telegram to avoid that api token can be worldwide readable.

@Vskilet Vskilet closed this Jun 25, 2019
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 (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants