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

go-neb's secretFile support changes the semantics of the template options #151422

Open
grahamc opened this issue Dec 20, 2021 · 3 comments
Open
Labels
0.kind: bug Something is broken 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS

Comments

@grahamc
Copy link
Member

grahamc commented Dec 20, 2021

Describe the bug

The syntax inside templates is different depending on if secretFile is used or not, this makes the templates non-portable and produces confusing results.

For example, without a secret file the template in this config is valid:

{
  services.go-neb = {
    config = {
      clients = [
        {
          UserId = "@bot:nixos.org";
          AccessToken = "SomeAccessToken";
          HomeServerUrl = "https://nixos.ems.host";
          Sync = true;
          AutoJoinRooms = true;
          DisplayName = "Bot";
        }
      ];
      services = [
        {
          ID = "alertmanager_service";
          Type = "alertmanager";
          UserId = "@bot:nixos.org";
          Config.rooms."!QLQqibtFaVtDgurUAE:nixos.org" = {
            html_template = ''
              {{range .Alerts -}}
                {{ $severity := index .Labels "severity" }}
                <b>{{ $severity }}</b>
              {{end -}}
            '';
            msg_type = "m.text";
          };
        }
      ];
    };
  };
}

However, after adding a secretFile we get startup errors:

html template is invalid: template: htmlTemplate:2: unexpected \":=\" in command"

What is happening? In the rendered config, $severity has been replaced with an empty string:

html_template: "{{range .Alerts -}}\n  {{  := index .Labels \"severity\"\...

To fix this, I must change $severity to $$severity. However, $$severity is not valid if I don't specify a secretFile.

Expected behavior

The templates I provide should be valid whether or not I provide a secretFile.

Notify maintainers

cc @Mic92, @mweinelt

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

  • system: "x86_64-linux"
  • host os: Linux 5.10.84, NixOS, 21.11 (Porcupine)
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.4pre20210810_a6ba313
  • nixpkgs: /nix/store/33zzxrj3kzlyv22qm3p7a703dp69cshd-source

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
# a list of nixos modules affected by the problem
module:
- services.go-neb
@grahamc grahamc added the 0.kind: bug Something is broken label Dec 20, 2021
@lheckemann
Copy link
Member

Similar to #126083. Any chance that go-neb supports secret files itself so it can be fixed like prometheus was in #144984?

@grahamc
Copy link
Member Author

grahamc commented Dec 20, 2021

It doesn't today but I suppose it surely could :).

@veprbl veprbl added the 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS label Dec 20, 2021
@Mic92
Copy link
Member

Mic92 commented Feb 25, 2022

Does envsubst not ignore unknown variables?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS
Projects
None yet
Development

No branches or pull requests

4 participants