1 { config, lib, pkgs, ... }:
3 cfg = config.services.go-neb;
5 settingsFormat = pkgs.formats.yaml {};
6 configFile = settingsFormat.generate "config.yaml" cfg.config;
8 options.services.go-neb = {
9 enable = lib.mkEnableOption "an extensible matrix bot written in Go";
11 bindAddress = lib.mkOption {
13 description = "Port (and optionally address) to listen on.";
17 secretFile = lib.mkOption {
18 type = lib.types.nullOr lib.types.path;
20 example = "/run/keys/go-neb.env";
22 Environment variables from this file will be interpolated into the
23 final config file using envsubst with this syntax: `$ENVIRONMENT`
25 The file should contain lines formatted as `SECRET_VAR=SECRET_VALUE`.
26 This is useful to avoid putting secrets into the nix store.
30 baseUrl = lib.mkOption {
32 description = "Public-facing endpoint that can receive webhooks.";
35 config = lib.mkOption {
36 inherit (settingsFormat) type;
38 Your {file}`config.yaml` as a Nix attribute set.
39 See [config.sample.yaml](https://github.com/matrix-org/go-neb/blob/master/config.sample.yaml)
45 config = lib.mkIf cfg.enable {
46 systemd.services.go-neb = let
47 finalConfigFile = if cfg.secretFile == null then configFile else "/var/run/go-neb/config.yaml";
49 description = "Extensible matrix bot written in Go";
50 after = [ "network.target" ];
51 wantedBy = [ "multi-user.target" ];
53 BASE_URL = cfg.baseUrl;
54 BIND_ADDRESS = cfg.bindAddress;
55 CONFIG_FILE = finalConfigFile;
59 ExecStartPre = lib.optional (cfg.secretFile != null)
60 ("+" + pkgs.writeShellScript "pre-start" ''
62 export $(xargs < ${cfg.secretFile})
63 ${pkgs.envsubst}/bin/envsubst -i "${configFile}" > ${finalConfigFile}
64 chown go-neb ${finalConfigFile}
66 RuntimeDirectory = "go-neb";
67 ExecStart = "${pkgs.go-neb}/bin/go-neb";
74 meta.maintainers = with lib.maintainers; [ hexa maralorn ];