Skip to content

Instantly share code, notes, and snippets.

@kampka
Created May 22, 2020 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kampka/a3d05fde767aabea612a040129ffa259 to your computer and use it in GitHub Desktop.
Save kampka/a3d05fde767aabea612a040129ffa259 to your computer and use it in GitHub Desktop.
Service declaration for matrix-appservice-slack on NixOS
{ config, pkgs, lib, ... }:
let
app = pkgs.callPackage ./package.nix {};
cfg = config.kampka.services.matrix-appservice-slack ;
configFile = pkgs.writeText "matrix-appservice-slack-config.yaml" "${builtins.readFile ./config.yaml}";
registrationFile = pkgs.writeText "matrix-appservice-slack-registration.yaml" "${builtins.readFile ./registration.yaml}";
in{
options.kampka.services.matrix-appservice-slack = with lib; {
enable = mkEnableOption "matrix-appservice-slack";
};
config = lib.mkIf cfg.enable {
services.postgresql = {
enable = lib.mkDefault true;
ensureDatabases = [ "slackbridge" ];
ensureUsers = [{
name = "slackbridge";
ensurePermissions = { "DATABASE slackbridge" = "ALL PRIVILEGES"; };
}];
};
users.users.slackbridge = {
description = "matrix-appservice-slack";
group = "matrix-synapse";
isSystemUser = true;
};
systemd.services.matrix-appservice-slack = {
description = "matrix-appservice-slack";
after = [ "network.target" ] ++ lib.optional config.services.postgresql.enable "postgresql.service" ;
wantedBy = [ "multi-user.target" ];
serviceConfig = {
User = "slackbridge";
Group = "matrix-synapse";
WorkingDirectory = "${app}/lib/node_modules/matrix-appservice-slack";
ExecStart = ''
${app}/bin/matrix-appservice-slack -c ${configFile} -f ${registrationFile}
'';
Restart = "on-failure";
};
};
services.matrix-synapse.app_service_config_files = [ registrationFile ];
networking.firewall = {
allowedTCPPorts = [ 9898 ];
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment