8 cfg = config.services.go-neb;
10 settingsFormat = pkgs.formats.yaml { };
11 configFile = settingsFormat.generate "config.yaml" cfg.config;
14 options.services.go-neb = {
15 enable = lib.mkEnableOption "an extensible matrix bot written in Go";
17 bindAddress = lib.mkOption {
19 description = "Port (and optionally address) to listen on.";
23 secretFile = lib.mkOption {
24 type = lib.types.nullOr lib.types.path;
26 example = "/run/keys/go-neb.env";
28 Environment variables from this file will be interpolated into the
29 final config file using envsubst with this syntax: `$ENVIRONMENT`
31 The file should contain lines formatted as `SECRET_VAR=SECRET_VALUE`.
32 This is useful to avoid putting secrets into the nix store.
36 baseUrl = lib.mkOption {
38 description = "Public-facing endpoint that can receive webhooks.";
41 config = lib.mkOption {
42 inherit (settingsFormat) type;
44 Your {file}`config.yaml` as a Nix attribute set.
45 See [config.sample.yaml](https://github.com/matrix-org/go-neb/blob/master/config.sample.yaml)
51 config = lib.mkIf cfg.enable {
52 systemd.services.go-neb =
54 finalConfigFile = if cfg.secretFile == null then configFile else "/var/run/go-neb/config.yaml";
57 description = "Extensible matrix bot written in Go";
58 after = [ "network.target" ];
59 wantedBy = [ "multi-user.target" ];
61 BASE_URL = cfg.baseUrl;
62 BIND_ADDRESS = cfg.bindAddress;
63 CONFIG_FILE = finalConfigFile;
67 ExecStartPre = lib.optional (cfg.secretFile != null) (
69 + pkgs.writeShellScript "pre-start" ''
71 export $(xargs < ${cfg.secretFile})
72 ${pkgs.envsubst}/bin/envsubst -i "${configFile}" > ${finalConfigFile}
73 chown go-neb ${finalConfigFile}
76 RuntimeDirectory = "go-neb";
77 ExecStart = "${pkgs.go-neb}/bin/go-neb";
84 meta.maintainers = with lib.maintainers; [