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/znc: More flexible module, cleanups #45470

Merged
merged 3 commits into from Oct 17, 2018
Merged

Conversation

infinisil
Copy link
Member

@infinisil infinisil commented Aug 22, 2018

Motivation for this change

This is the follow up on #41467, which I needed to clean up for a while, and I finally did it.

This adds a new option services.znc.config, which can represent the full ZNC configuration as a Nix value, see its description for more info. It's much more flexible than the older services.znc.confOptions.* options. It allows the user to override previously fixed values and to set options that the module system might not know about, as it happens on every ZNC upgrade.

Because this new option doesn't know about all valid ZNC options however, it can't do any checks for it to be correct. This doesn't have an easy solution unfortunately. It will generate a syntactically valid file though.

Other changes:

  • Clean up everything, remove unused options

It's now possible to:

  • Have multiple users
  • Set channels as detached
  • Define QuitMsg
  • And everything else that wasn't previously possible

The new config option will get converted into the xml-like syntax znc expects, works with all config values, see https://wiki.znc.in/Configuration. This is what one could look like:

services.znc.useLegacyConfig = false;
services.znc.config = {
  # Listener.l.Port = 5000; <- This is added by default
  LoadModule = [ "webadmin" "adminlog" ];
  User.paul = {
    Admin = true;
    Nick = "paul";
    AltNick = "paul1";
    LoadModule = [ "chansaver" "controlpanel" ];
    Network.freenode = {
      Server = "chat.freenode.net +6697";
      LoadModule = [ "simple_away" ];
      Chan = {
        "#nixos" = { Detached = false; };
        "##linux" = { Disabled = true; };
      };
    };
    Pass.password = {
      Method = "sha256";
      Hash = "e2ce303c7ea75c571d80d8540a8699b46535be6a085be3414947d638e48d9e93";
      Salt = "l5Xryew4g*!oa(ECfX2o";
    };
  };
}

To see the current config, you can either inspect it via nix-instantiate:

$ nix-instantiate --eval --strict '<nixpkgs/nixos>' -A config.services.znc.config
{ Listener = { l = { IPv4 = true; IPv6 = true; Port = 5000; SSL = true; }; }; LoadModule = [ "webadmin" "adminlog" ]; User = { znc = { Admin = true; AltNick = "znc-user_"; Ident = "znc-user"; LoadModule = [ "chansaver" "controlpanel" ]; Network = { freenode = { Chan = { }; LoadModule = [ "simple_away" ]; Server = "test +6697 "; extraConfig = null; }; }; Nick = "znc-user"; RealName = "znc-user"; extraConfig = [ "<Pass password>\n     Method = sha256\n     Hash = e2ce303c7ea75c571d80d8540a8699b46535be6a085be3414947d638e48d9e93\n     Salt = l5Xryew4g*!oa(ECfX2o\n</Pass>\n" ]; }; }; Version = "1.7.1"; }

Or directly build the config file and look at that:

$ nix-build '<nixpkgs/nixos>' -A config.services.znc.configFile
/nix/store/330zxcdjai2ciw3risy9iqymnda46i2i-znc-generated.conf

Unless you disable the new option services.znc.useLegacyConfig, the values in services.znc.confOptions.* will also have influence on services.znc.config, such as a default list of modules, default user, etc. This isn't problematic, the new config options handles merging without trouble.

Things done

Ping @nocoolnametom @viric @schneefux @LnL7

Review commit by commit

  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • 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 nox --run "nox-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)
  • Fits CONTRIBUTING.md.

'';
};

confOptions = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this removes options it definitively need a changelog entry.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an entry in the release notes for the removed options (the ones that can't be warned against by the module system, the ones in the submodule)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, forgot to remove this one when I got to the end. 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean it is a valid point though!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, didn't look at that part in depth and assumed it was compatible. So I guess good thing I forgot.

description = "ZNC Server";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
serviceConfig = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should have restartIfChanged = false

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any compelling reason for that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid disconnecting.

config = {
Version = (builtins.parseDrvName pkgs.znc.name).version;
Listener.l.Port = mkDefault 5000;
Listener.l.SSL = mkDefault true;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default for ZNC is to not use SSL, so I explicitly set the default here to turn it on, consistent with the defaults in the old-style config.

@infinisil
Copy link
Member Author

I have now tested this with my own ZNC setup, and I think this is ready to be merged.

Ping @LnL7 @dustinlacewell

@dhess
Copy link
Contributor

dhess commented Oct 12, 2018

I'm a ZNC user and this looks good to me. I would request that a (near) future change is made to keep the secret (password and/or password hash) out of the config file so that it's not written to the store, however.

@@ -200,6 +200,14 @@ $ nix-instantiate -E '(import &lt;nixpkgsunstable&gt; {}).gitFull'
from your config without any issues.
</para>
</listitem>
<listitem>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to move this to 19.03

description = "ZNC Server";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
serviceConfig = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid disconnecting.

Copy link
Member

@LnL7 LnL7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, but I don't run znc on nixos.

Move legacy options to separate file
@infinisil
Copy link
Member Author

Rebased on master to get the release note manual file on 19.03 and moved the release notes there

I'll ask around a bit more, but if nobody complains I'll merge this myself.

@infinisil
Copy link
Member Author

Worth mentioning: The first and second commit don't produce a working znc config, so they're not ideal for bisecting, but it would take a lot of work to split them up better. I could squash them if that's desired.

@infinisil
Copy link
Member Author

Squashed the 2 relevant commits into one, made more sense like that

@infinisil
Copy link
Member Author

The nixos/znc: add config option commit is the meaty one.

This option represents the ZNC configuration as a Nix value. It will be
converted to a syntactically valid file. This provides:
- Flexibility: Any ZNC option can be used
- Modularity: These values can be set from any NixOS module and will be
merged correctly
- Overridability: Default values can be overridden

Also done:
Remove unused/unneeded options, mkRemovedOptionModule unfortunately doesn't work
inside submodules (yet). The options userName and modulePackages were never used
to begin with
@infinisil
Copy link
Member Author

Pushed some minor description updates

@infinisil infinisil merged commit e443bbf into NixOS:master Oct 17, 2018
@infinisil infinisil deleted the znc-config branch October 17, 2018 01:01
infinisil added a commit to infinisil/system that referenced this pull request Oct 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants