2020-06-01 20:31:10 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.services.go-neb;
|
|
|
|
|
2021-06-22 07:07:50 +00:00
|
|
|
settingsFormat = pkgs.formats.yaml {};
|
|
|
|
configFile = settingsFormat.generate "config.yaml" cfg.config;
|
2020-06-01 20:31:10 +00:00
|
|
|
in {
|
|
|
|
options.services.go-neb = {
|
2024-08-28 19:19:09 +00:00
|
|
|
enable = lib.mkEnableOption "an extensible matrix bot written in Go";
|
2020-06-01 20:31:10 +00:00
|
|
|
|
2024-08-28 19:19:09 +00:00
|
|
|
bindAddress = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2020-06-01 20:31:10 +00:00
|
|
|
description = "Port (and optionally address) to listen on.";
|
|
|
|
default = ":4050";
|
|
|
|
};
|
|
|
|
|
2024-08-28 19:19:09 +00:00
|
|
|
secretFile = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.path;
|
2021-06-22 07:07:50 +00:00
|
|
|
default = null;
|
|
|
|
example = "/run/keys/go-neb.env";
|
|
|
|
description = ''
|
|
|
|
Environment variables from this file will be interpolated into the
|
|
|
|
final config file using envsubst with this syntax: `$ENVIRONMENT`
|
|
|
|
or `''${VARIABLE}`.
|
|
|
|
The file should contain lines formatted as `SECRET_VAR=SECRET_VALUE`.
|
|
|
|
This is useful to avoid putting secrets into the nix store.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-28 19:19:09 +00:00
|
|
|
baseUrl = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2020-06-01 20:31:10 +00:00
|
|
|
description = "Public-facing endpoint that can receive webhooks.";
|
|
|
|
};
|
|
|
|
|
2024-08-28 19:19:09 +00:00
|
|
|
config = lib.mkOption {
|
2021-06-22 07:07:50 +00:00
|
|
|
inherit (settingsFormat) type;
|
2020-06-01 20:31:10 +00:00
|
|
|
description = ''
|
|
|
|
Your {file}`config.yaml` as a Nix attribute set.
|
|
|
|
See [config.sample.yaml](https://github.com/matrix-org/go-neb/blob/master/config.sample.yaml)
|
|
|
|
for possible options.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-08-28 19:19:09 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
2021-06-22 07:07:50 +00:00
|
|
|
systemd.services.go-neb = let
|
|
|
|
finalConfigFile = if cfg.secretFile == null then configFile else "/var/run/go-neb/config.yaml";
|
|
|
|
in {
|
2020-06-01 20:31:10 +00:00
|
|
|
description = "Extensible matrix bot written in Go";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
environment = {
|
|
|
|
BASE_URL = cfg.baseUrl;
|
|
|
|
BIND_ADDRESS = cfg.bindAddress;
|
2021-06-22 07:07:50 +00:00
|
|
|
CONFIG_FILE = finalConfigFile;
|
2020-06-01 20:31:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
serviceConfig = {
|
2021-06-22 07:07:50 +00:00
|
|
|
ExecStartPre = lib.optional (cfg.secretFile != null)
|
2023-04-03 23:01:49 +00:00
|
|
|
("+" + pkgs.writeShellScript "pre-start" ''
|
2021-06-22 07:07:50 +00:00
|
|
|
umask 077
|
|
|
|
export $(xargs < ${cfg.secretFile})
|
|
|
|
${pkgs.envsubst}/bin/envsubst -i "${configFile}" > ${finalConfigFile}
|
|
|
|
chown go-neb ${finalConfigFile}
|
|
|
|
'');
|
|
|
|
RuntimeDirectory = "go-neb";
|
2020-06-01 20:31:10 +00:00
|
|
|
ExecStart = "${pkgs.go-neb}/bin/go-neb";
|
2021-06-22 07:07:50 +00:00
|
|
|
User = "go-neb";
|
2020-06-01 20:31:10 +00:00
|
|
|
DynamicUser = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-08-28 19:19:09 +00:00
|
|
|
meta.maintainers = with lib.maintainers; [ hexa maralorn ];
|
2020-06-01 20:31:10 +00:00
|
|
|
}
|