Unverified Commit 48d6418a authored by Nick Cao's avatar Nick Cao Committed by GitHub
Browse files

Merge pull request #215696 from fee1-dead-contrib/matrix-appservice-discord.customize-package

nixos/appservice-discord: customizable `package`
parents 0fdc4871 e391cf36
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ with lib;
let
  dataDir = "/var/lib/matrix-appservice-discord";
  registrationFile = "${dataDir}/discord-registration.yaml";
  appDir = "${pkgs.matrix-appservice-discord}/${pkgs.matrix-appservice-discord.passthru.nodeAppDir}";
  cfg = config.services.matrix-appservice-discord;
  opt = options.services.matrix-appservice-discord;
  # TODO: switch to configGen.json once RFC42 is implemented
@@ -16,6 +15,15 @@ in {
    services.matrix-appservice-discord = {
      enable = mkEnableOption (lib.mdDoc "a bridge between Matrix and Discord");

      package = mkOption {
        type = types.package;
        default = pkgs.matrix-appservice-discord;
        defaultText = literalExpression "pkgs.matrix-appservice-discord";
        description = lib.mdDoc ''
          Which package of matrix-appservice-discord to use.
        '';
      };

      settings = mkOption rec {
        # TODO: switch to types.config.json as prescribed by RFC42 once it's implemented
        type = types.attrs;
@@ -114,7 +122,7 @@ in {

      preStart = ''
        if [ ! -f '${registrationFile}' ]; then
          ${pkgs.matrix-appservice-discord}/bin/matrix-appservice-discord \
          ${cfg.package}/bin/matrix-appservice-discord \
            --generate-registration \
            --url=${escapeShellArg cfg.url} \
            ${optionalString (cfg.localpart != null) "--localpart=${escapeShellArg cfg.localpart}"} \
@@ -135,13 +143,13 @@ in {

        DynamicUser = true;
        PrivateTmp = true;
        WorkingDirectory = appDir;
        WorkingDirectory = "${cfg.package}/${cfg.package.passthru.nodeAppDir}";
        StateDirectory = baseNameOf dataDir;
        UMask = "0027";
        EnvironmentFile = cfg.environmentFile;

        ExecStart = ''
          ${pkgs.matrix-appservice-discord}/bin/matrix-appservice-discord \
          ${cfg.package}/bin/matrix-appservice-discord \
            --file='${registrationFile}' \
            --config='${settingsFile}' \
            --port='${toString cfg.port}'