Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/go-neb: init #89327

Merged
merged 2 commits into from Jun 16, 2020
Merged

nixos/go-neb: init #89327

merged 2 commits into from Jun 16, 2020

Conversation

@mweinelt
Copy link
Member

mweinelt commented Jun 1, 2020

Motivation for this change

Go-neb is a matrix bot that was packaged in #87854. Now we deliver a simple module to easily set this up.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@tilpner @maralorn

@mweinelt mweinelt force-pushed the mweinelt:go-neb-module branch from d3bd8c2 to 0c47852 Jun 1, 2020
@mweinelt mweinelt force-pushed the mweinelt:go-neb-module branch 2 times, most recently from 07275bb to 537c8c2 Jun 1, 2020
@mweinelt mweinelt force-pushed the mweinelt:go-neb-module branch 2 times, most recently from f03d090 to 2195ace Jun 1, 2020
@mweinelt mweinelt marked this pull request as ready for review Jun 1, 2020
@mweinelt mweinelt requested a review from tilpner Jun 1, 2020
Copy link
Contributor

aanderse left a comment

Nice and simple module 👍

Even more bonus points if it comes with a NixOS test

nixos/modules/services/networking/go-neb.nix Outdated Show resolved Hide resolved
@maralorn
Copy link
Contributor

maralorn commented Jun 1, 2020

I have copied this module to my server and have alertmanager warnings (and a wikipedia bot) up and running with this.

{
  services.go-neb = {
    enable = true;
    baseUrl = "http://localhost";
    config = {
      clients = [{
        UserId = "@marabot:maralorn.de";
        AccessToken = config.m-0.private.matrix_marabot_token;
        HomeServerUrl = "https://matrix.maralorn.de";
        Sync = true;
        AutoJoinRooms = true;
        DisplayName = "marabot";
      }];
      realms = [ ];
      sessions = [ ];
      services = [
        {
          ID = "alertmanager_service";
          Type = "alertmanager";
          UserId = "@marabot:maralorn.de";
          Config = {
            webhook_url =
              "http://localhost:4050/services/hooks/YWxlcnRtYW5hZ2VyX3NlcnZpY2UK";
            rooms = {
              "!negVsngnYOmXYCLKiO:maralorn.de" = {
                text_template = ''
                  {{range .Alerts -}} [{{ .Status }}] {{index .Labels "alertname" }}: {{index .Annotations "description"}} {{ end -}}'';
                  html_template = ''
                    {{range .Alerts -}}
                      {{ $severity := index .Labels "severity" }}
                      {{ if eq .Status "firing" }}
                        {{ if eq $severity "critical"}}
                          <font color='red'><b>[FIRING - CRITICAL]</b></font>
                        {{ else if eq $severity "warning"}}
                          <font color='orange'><b>[FIRING - WARNING]</b></font>
                        {{ else }}
                          <b>[FIRING - {{ $severity }}]</b>
                        {{ end }}
                      {{ else }}
                        <font color='green'><b>[RESOLVED]</b></font>
                      {{ end }}
                      {{ index .Labels "alertname"}}:{{ index .Annotations "description"}}
                      <a href="{{ .GeneratorURL }}">source</a><br/>
                    {{end -}}
                    '';
                msg_type = "m.text"; # Must be either `m.text` or `m.notice`
              };
            };
          };
        }
        {
          ID = "wikipedia_service";
          Type = "wikipedia";
          UserID = "@marabot:maralorn.de"; # requires a Syncing client
          Config = { };
        }
      ];
    };
  };
}
@mweinelt mweinelt force-pushed the mweinelt:go-neb-module branch from 2195ace to a0b305b Jun 1, 2020
@mweinelt
Copy link
Member Author

mweinelt commented Jun 2, 2020

Simple test added.

@mweinelt mweinelt force-pushed the mweinelt:go-neb-module branch 2 times, most recently from d4dfe1f to 6724f8f Jun 2, 2020
@tilpner
Copy link
Member

tilpner commented Jun 2, 2020

In https://github.com/matrix-org/go-neb#quick-start, DATABASE_{TYPE,URL} are set, which is not replicated here. Where does this module store its state?

@maralorn
Copy link
Contributor

maralorn commented Jun 2, 2020

@tilpner the bot has two modes. Statefully saving the config in an sqlite DB or reading the config from a config file. So the DB you are mentioning is not data state but only for config state. We opted to support only the second option, because it supports the same features and is much more nix like.

@mweinelt
Copy link
Member Author

mweinelt commented Jun 2, 2020

@tilpner the bot has two modes. Statefully saving the config in an sqlite DB or reading the config from a config file. So the DB you are mentioning is not data state but only for config state. We opted to support only the second option, because it supports the same features and is much more nix like.

The partial source for this statement is here: https://github.com/matrix-org/go-neb/blob/81842c69f831b7dccaa685ccacbbe218d059d76c/config.sample.yaml#L5-L9

@mweinelt mweinelt force-pushed the mweinelt:go-neb-module branch from 6724f8f to 252dc17 Jun 2, 2020
@tilpner
Copy link
Member

tilpner commented Jun 3, 2020

I see. It surprised me that they were exclusive modes, I was hoping it would operate in a hybrid mode, as e.g. reliable RSS feed consumption requires state.

Supporting only the declarative mode in this module is reasonable though. Thanks for writing it! :)

@tilpner
tilpner approved these changes Jun 3, 2020
@maralorn
Copy link
Contributor

maralorn commented Jun 3, 2020

@aanderse Are you also satisfied with the state of this?

Copy link
Contributor

aanderse left a comment

Yeah this is a winner in my books. Thanks for the extra work on this one. Bonus points for all!

I'm not a subject matter expert so I wouldn't think to merge this... but if you're just waiting for a merge and everyone agrees I'm certainly happy to do so based on that 👍

@aanderse
Copy link
Contributor

aanderse commented Jun 3, 2020

... and just as I say that I notice the test isn't added to the list of tests. Please add and we're good.

Simple test to start the unit with a dummy client and a dummy service
and check if it can receive webhooks.
@mweinelt mweinelt force-pushed the mweinelt:go-neb-module branch from 252dc17 to d72a736 Jun 3, 2020
@mweinelt
Copy link
Member Author

mweinelt commented Jun 3, 2020

@maralorn
Copy link
Contributor

maralorn commented Jun 10, 2020

@aanderse Can you maybe point us to a subject matter expert? Otherwise I'd opt for the merge.

@aanderse
Copy link
Contributor

aanderse commented Jun 11, 2020

@maralorn maybe @Ma27 knows a thing or two... but this looks really good, so I'll merge by end of day if no one has any objections.

Thanks! 🎉

@aanderse
Copy link
Contributor

aanderse commented Jun 11, 2020

@GrahamcOfBorg test go-neb

@aanderse aanderse merged commit b6108e0 into NixOS:master Jun 16, 2020
16 checks passed
16 checks passed
Evaluation Performance Report Evaluator Performance Report
Details
grahamcofborg-eval ^.^!
Details
grahamcofborg-eval-check-maintainers matching changed paths to changed attrs...
Details
grahamcofborg-eval-check-meta config.nix: checkMeta = true
Details
grahamcofborg-eval-darwin nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="d72a736"; rev="d72a7360c27f5346b7212a4d8611b38e3dd11a84"; } ./pkgs/t
Details
grahamcofborg-eval-lib-tests nix-build --arg pkgs import ./. {} ./lib/tests/release.nix
Details
grahamcofborg-eval-nixos nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="d72a736"; rev="d72a7360c27f5346b7212a4d8611b38e3dd11a84"; } ./nixos/
Details
grahamcofborg-eval-nixos-manual nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="d72a736"; rev="d72a7360c27f5346b7212a4d8611b38e3dd11a84"; } ./nixos/
Details
grahamcofborg-eval-nixos-options nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="d72a736"; rev="d72a7360c27f5346b7212a4d8611b38e3dd11a84"; } ./nixos/
Details
grahamcofborg-eval-nixpkgs-manual nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="d72a736"; rev="d72a7360c27f5346b7212a4d8611b38e3dd11a84"; } ./pkgs/t
Details
grahamcofborg-eval-nixpkgs-tarball nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="d72a736"; rev="d72a7360c27f5346b7212a4d8611b38e3dd11a84"; } ./pkgs/t
Details
grahamcofborg-eval-nixpkgs-unstable-jobset nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="d72a736"; rev="d72a7360c27f5346b7212a4d8611b38e3dd11a84"; } ./pkgs/t
Details
grahamcofborg-eval-package-list nix-env -qa --json --file .
Details
grahamcofborg-eval-package-list-no-aliases nix-env -qa --json --file . --arg config { allowAliases = false; }
Details
tests.go-neb on aarch64-linux Success
Details
tests.go-neb on x86_64-linux Success
Details
@aanderse
Copy link
Contributor

aanderse commented Jun 16, 2020

Oops! Thanks team ❤️

@mweinelt mweinelt deleted the mweinelt:go-neb-module branch Jun 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.