From f01ccf4bbd6903e415b085db1b15cd6e4d979329 Mon Sep 17 00:00:00 2001 From: sefidel Date: Thu, 11 Jan 2024 17:34:43 +0900 Subject: feat(overlays/mautrix-signal-module)!: target Go version --- overlays/default.nix | 5 --- overlays/mautrix-signal-module.nix | 60 +++++++++++++++------------- overlays/python3-mautrix-0-19.nix | 82 -------------------------------------- 3 files changed, 33 insertions(+), 114 deletions(-) delete mode 100644 overlays/python3-mautrix-0-19.nix (limited to 'overlays') diff --git a/overlays/default.nix b/overlays/default.nix index 0dbd403..b1a2bf2 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,7 +1,2 @@ self: super: { - pythonPackagesExtensions = super.pythonPackagesExtensions ++ [ - (p-final: p-prev: { - mautrix_0_19 = super.python3Packages.callPackage ./python3-mautrix-0-19.nix { }; - }) - ]; } diff --git a/overlays/mautrix-signal-module.nix b/overlays/mautrix-signal-module.nix index 58878b9..983d635 100644 --- a/overlays/mautrix-signal-module.nix +++ b/overlays/mautrix-signal-module.nix @@ -7,11 +7,14 @@ let registrationFile = "${dataDir}/signal-registration.yaml"; cfg = config.services.mautrix-signal; settingsFormat = pkgs.formats.json { }; - settingsFile = + settingsFile = "${dataDir}/config.json"; + settingsFileUnsubstituted = settingsFormat.generate "mautrix-signal-config.json" cfg.settings; in { + # NOTE(2024-01-11): Upstream has been moved to a Go version. + # Environment-based credential setting might not work. options = { services.mautrix-signal = { enable = mkEnableOption (lib.mdDoc "Mautrix-Signal, a Matrix-Signal puppeting bridge."); @@ -44,28 +47,13 @@ in }; logging = { - version = 1; - - formatters.precise.format = "[%(levelname)s@%(name)s] %(message)s"; - - handlers.console = { - class = "logging.StreamHandler"; - formatter = "precise"; - }; - - loggers = { - mau.level = "INFO"; - - # prevent tokens from leaking in the logs: - # https://github.com/tulir/mautrix-telegram/issues/351 - aiohttp.level = "WARNING"; - }; - - # log to console/systemd instead of file - root = { - level = "INFO"; - handlers = [ "console" ]; - }; + min_level = "debug"; + writers = [ + { + type = "stdout"; + format = "pretty-colored"; + } + ]; }; }; example = literalExpression '' @@ -142,6 +130,7 @@ in after = [ "network-online.target" ] ++ cfg.serviceDependencies; path = [ pkgs.lottieconverter pkgs.ffmpeg-full ]; + # TODO(2023-01-11): Still relevant in Go version? # mautrix-signal tries to generate a dotfile in the home directory of # the running user if using a postgresql database: # @@ -155,17 +144,32 @@ in environment.HOME = dataDir; preStart = '' + # substitute the settings file by environment variables + # in this case read from EnvironmentFile + test -f '${settingsFile}' && rm -f '${settingsFile}' + old_umask=$(umask) + umask 0177 + ${pkgs.envsubst}/bin/envsubst \ + -o '${settingsFile}' \ + -i '${settingsFileUnsubstituted}' \ + umask $old_umask + # generate the appservice's registration file if absent if [ ! -f '${registrationFile}' ]; then ${cfg.package}/bin/mautrix-signal \ --generate-registration \ - --base-config='${cfg.package}/${cfg.package.pythonModule.sitePackages}/mautrix_signal/example-config.yaml' \ --config='${settingsFile}' \ --registration='${registrationFile}' fi - '' + lib.optionalString (cfg.package ? alembic) '' - # run automatic database init and migration scripts - ${cfg.package.alembic}/bin/alembic -x config='${settingsFile}' upgrade head + chmod 640 ${registrationFile} + + umask 0177 + ${pkgs.yq}/bin/yq -s '.[0].appservice.as_token = .[1].as_token + | .[0].appservice.hs_token = .[1].hs_token + | .[0]' '${settingsFile}' '${registrationFile}' \ + > '${settingsFile}.tmp' + mv '${settingsFile}.tmp' '${settingsFile}' + umask $old_umask ''; serviceConfig = { @@ -190,6 +194,8 @@ in ${cfg.package}/bin/mautrix-signal \ --config='${settingsFile}' ''; + + restartTriggers = [settingsFileUnsubstituted]; }; }; }; diff --git a/overlays/python3-mautrix-0-19.nix b/overlays/python3-mautrix-0-19.nix deleted file mode 100644 index b97730f..0000000 --- a/overlays/python3-mautrix-0-19.nix +++ /dev/null @@ -1,82 +0,0 @@ -{ lib -, buildPythonPackage -, fetchFromGitHub -, pythonOlder - # deps -, aiohttp -, attrs -, yarl - # optional deps -, python-magic -, python-olm -, unpaddedbase64 -, pycryptodome - # check deps -, pytestCheckHook -, pytest-asyncio -, aiosqlite -, sqlalchemy -, asyncpg -}: - -buildPythonPackage rec { - pname = "mautrix"; - version = "0.19.16"; - format = "setuptools"; - - disabled = pythonOlder "3.8"; - - src = fetchFromGitHub { - owner = "mautrix"; - repo = "python"; - rev = "refs/tags/v${version}"; - hash = "sha256-aZlc4+J5Q+N9qEzGUMhsYguPdUy+E5I06wrjVyqvVDk="; - }; - - propagatedBuildInputs = [ - aiohttp - attrs - yarl - ]; - - passthru.optional-dependencies = { - detect_mimetype = [ - python-magic - ]; - encryption = [ - python-olm - unpaddedbase64 - pycryptodome - ]; - }; - - nativeCheckInputs = [ - pytestCheckHook - ]; - - checkInputs = [ - pytest-asyncio - aiosqlite - sqlalchemy - asyncpg - ] ++ passthru.optional-dependencies.encryption; - - SQLALCHEMY_SILENCE_UBER_WARNING = 1; - - disabledTestPaths = [ - # sqlalchemy 2 unsupported - "mautrix/client/state_store/tests/store_test.py" - ]; - - pythonImportsCheck = [ - "mautrix" - ]; - - meta = with lib; { - description = "Asyncio Matrix framework"; - homepage = "https://github.com/tulir/mautrix-python"; - changelog = "https://github.com/mautrix/python/releases/tag/v${version}"; - license = licenses.mpl20; - maintainers = with maintainers; [ nyanloutre ma27 sumnerevans nickcao ]; - }; -} -- cgit 1.4.1