1 { config, lib, pkgs, ... }:
6 cfg = config.services.go-neb;
8 settingsFormat = pkgs.formats.yaml {};
9 configFile = settingsFormat.generate "config.yaml" cfg.config;
11 options.services.go-neb = {
12 enable = mkEnableOption (lib.mdDoc "Extensible matrix bot written in Go");
14 bindAddress = mkOption {
16 description = lib.mdDoc "Port (and optionally address) to listen on.";
20 secretFile = mkOption {
21 type = types.nullOr types.path;
23 example = "/run/keys/go-neb.env";
24 description = lib.mdDoc ''
25 Environment variables from this file will be interpolated into the
26 final config file using envsubst with this syntax: `$ENVIRONMENT`
28 The file should contain lines formatted as `SECRET_VAR=SECRET_VALUE`.
29 This is useful to avoid putting secrets into the nix store.
35 description = lib.mdDoc "Public-facing endpoint that can receive webhooks.";
39 inherit (settingsFormat) type;
40 description = lib.mdDoc ''
41 Your {file}`config.yaml` as a Nix attribute set.
42 See [config.sample.yaml](https://github.com/matrix-org/go-neb/blob/master/config.sample.yaml)
48 config = mkIf cfg.enable {
49 systemd.services.go-neb = let
50 finalConfigFile = if cfg.secretFile == null then configFile else "/var/run/go-neb/config.yaml";
52 description = "Extensible matrix bot written in Go";
53 after = [ "network.target" ];
54 wantedBy = [ "multi-user.target" ];
56 BASE_URL = cfg.baseUrl;
57 BIND_ADDRESS = cfg.bindAddress;
58 CONFIG_FILE = finalConfigFile;
62 ExecStartPre = lib.optional (cfg.secretFile != null)
63 (pkgs.writeShellScript "pre-start" ''
65 export $(xargs < ${cfg.secretFile})
66 ${pkgs.envsubst}/bin/envsubst -i "${configFile}" > ${finalConfigFile}
67 chown go-neb ${finalConfigFile}
69 PermissionsStartOnly = true;
70 RuntimeDirectory = "go-neb";
71 ExecStart = "${pkgs.go-neb}/bin/go-neb";
78 meta.maintainers = with maintainers; [ hexa maralorn ];