nixos/mpd: allow to explicitly close firewall without a warning

Fixes #484912 and addresses the comments here:

https://github.com/NixOS/nixpkgs/pull/456989#discussion_r2642740944
This commit is contained in:
Doron Behar
2026-01-29 14:20:48 +02:00
parent 2e04ce74b9
commit 9638294b1d
+12 -6
View File
@@ -143,9 +143,13 @@ in
};
openFirewall = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Open ports in the firewall for mpd.";
type = lib.types.nullOr lib.types.bool;
default = null;
description = ''
Open ports in the firewall for mpd. If `null` (default), you might
get a warning asking you to set it explicitly to `true` or `false`,
depending upon the value of `services.mpd.settings.bind_to_address`.
'';
};
settings = lib.mkOption {
@@ -378,9 +382,9 @@ in
])
|| (lib.hasPrefix "/" cfg.settings.bind_to_address)
)
&& !cfg.openFirewall
&& (isNull cfg.openFirewall)
)
"Using '${cfg.settings.bind_to_address}' as services.mpd.settings.bind_to_address without enabling services.mpd.openFirewall, might prevent you from accessing MPD from other clients.";
"Using '${cfg.settings.bind_to_address}' as services.mpd.settings.bind_to_address without enabling services.mpd.openFirewall, might prevent you from accessing MPD from other clients. To suppress this warning, set services.mpd.openFirewall explicitly to `false`";
# install mpd units
systemd.packages = [ pkgs.mpd ];
@@ -438,7 +442,9 @@ in
};
};
networking.firewall.allowedTCPPorts = lib.optionals cfg.openFirewall [ cfg.settings.port ];
networking.firewall.allowedTCPPorts = lib.optionals (
builtins.isBool cfg.openFirewall && cfg.openFirewall
) [ cfg.settings.port ];
users.users = lib.optionalAttrs (cfg.user == name) {
${name} = {