NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.08k stars 14.06k forks source link

services.mjolnir.pantalaimon.options has no effect #146350

Open sumnerevans opened 2 years ago

sumnerevans commented 2 years ago

Describe the bug

The services.mjolnir.pantalaimon.options option has no effect.

For example, given the following config:

  services.mjolnir = {
    homeserverUrl = "http://localhost:8008";

    pantalaimon = {
      enable = true;
      username = "...";
      passwordFile = "...";
      options.listenPort = 8100;
    };
  };

running nixos-rebuild switch and then inspecting with nixos-option services.pantalaimon-headless.instances gives:

Value:
{ mjolnir = {
  dataPath = "/var/lib/pantalaimon-mjolnir";
  extraSettings = { };
  homeserver = "http://localhost:8008";
  listenAddress = "localhost";
  listenPort = 8009;
  logLevel = "warning";
  ssl = true;
}; }

Note that the port is wrong.

If I manually add services.pantalaimon-headless.instances.mjolnir.listenPort = 8100; then I can achieve the desired affect, but that is not a great situation.

Steps To Reproduce

Steps to reproduce the behavior:

  1. use the above config
  2. observe that it's listening on the wrong port

Expected behavior

the setting should work

Notify maintainers

@jojosch

Metadata

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

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.10.76, NixOS, 21.11 (Porcupine)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.5pre20211007_844dd90`
 - channels(root): `"nixos-21.11pre331460.931ab058daa"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
# a list of nixos modules affected by the problem
module: pantalaimon
jojosch commented 2 years ago

Hmm, I tried fixing it but I'm not really able to, probably due to a lack of knowledge in NixOS modules. The mjolnir-module was more or less my fist "real" NixOS module.


In the mjolnir module when merging the { homeserver = cfg.homeserverUrl; } and cfg.pantalaimon.options there were brackets missing:

nix-repl> lib.mkIf true { homeserver = "https://matrix.org"; } // { listenPort = 8100; }
{ _type = "if"; condition = true; content = { ... }; listenPort = 8100; }

vs

nix-repl> lib.mkIf true ({ homeserver = "https://matrix.org"; } // { listenPort = 8100; })
{ _type = "if"; condition = true; content = { ... }; }

but when using the fixed version I get the following error (e.g. when trying to run the mjolnir test):

error: The option `services.mjolnir.pantalaimon.options.homeserver' is used but not defined.
(use '--show-trace' to show detailed location information)

When setting a default value for the homeserver option the error goes away but the homeserver value then cannot be changed from the default value defined in pantalaimon-options.nix ... but the listenPort, listenAddress and other options can be changed and appear in the generated config ...