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