-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
nixos/firewalld: init #398587
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
Merged
Merged
nixos/firewalld: init #398587
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cb28578
nixos/firewalld: init
Prince213 87882c1
nixos/firewall: add firewalld backend
Prince213 3a7a4fb
nixos/podman: don't open ports for firewalld
Prince213 3160f3b
nixos/netbird: use firewalld zone
Prince213 2051b59
nixos/tests/firewall: add firewalld backend
Prince213 9ca60db
nixos/tests/firewalld: init
Prince213 bd3e75b
nixos/kodi: add firewalld files
Prince213 1f6f021
nixos/libvirtd: add firewalld files
Prince213 14105a5
nixos/wivrn: add firewalld files
Prince213 6f2b594
nixos/doc/rl-25.11: add firewalld
Prince213 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Prince213 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| { config, lib, ... }: | ||
|
|
||
| let | ||
| cfg = config.networking.firewall; | ||
| in | ||
| { | ||
| config = lib.mkIf (cfg.enable && cfg.backend == "firewalld") { | ||
| assertions = [ | ||
| { | ||
| assertion = cfg.interfaces == { }; | ||
| message = '' | ||
| Per interface configurations is not supported with the firewalld based firewall. | ||
| Create zones with `services.firewalld.zones` instead. | ||
| ''; | ||
| } | ||
| ]; | ||
|
|
||
| boot.kernel.sysctl."net.ipv4.conf.all.rp_filter" = | ||
| if cfg.checkReversePath == false then | ||
| 0 | ||
| else if cfg.checkReversePath == "loose" then | ||
| 1 | ||
| else | ||
| 2; | ||
|
|
||
| services.firewalld = { | ||
Aleksanaa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| settings = { | ||
| DefaultZone = lib.mkDefault "nixos-fw-default"; | ||
| LogDenied = | ||
| if cfg.logRefusedConnections then | ||
| (if cfg.logRefusedUnicastsOnly then "unicast" else "all") | ||
| else | ||
| "off"; | ||
| IPv6_rpfilter = | ||
| if cfg.checkReversePath == false then | ||
| "no" | ||
| else | ||
| let | ||
| mode = if cfg.checkReversePath == true then "strict" else cfg.checkReversePath; | ||
| suffix = if cfg.filterForward then "" else "-forward"; | ||
| in | ||
| "${mode}${suffix}"; | ||
| }; | ||
| zones = { | ||
| nixos-fw-default = { | ||
| target = if cfg.rejectPackets then "%%REJECT%%" else "DROP"; | ||
| icmpBlockInversion = true; | ||
| icmpBlocks = lib.mkIf cfg.allowPing [ "echo-request" ]; | ||
| ports = | ||
| let | ||
| f = protocol: port: { inherit protocol port; }; | ||
| tcpPorts = map (f "tcp") (cfg.allowedTCPPorts ++ cfg.allowedTCPPortRanges); | ||
| udpPorts = map (f "udp") (cfg.allowedUDPPorts ++ cfg.allowedUDPPortRanges); | ||
| in | ||
| tcpPorts ++ udpPorts; | ||
| }; | ||
| trusted.interfaces = cfg.trustedInterfaces; | ||
| }; | ||
| }; | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| { | ||
| config, | ||
| lib, | ||
| pkgs, | ||
| ... | ||
| }: | ||
|
|
||
| let | ||
| cfg = config.services.firewalld; | ||
| paths = pkgs.buildEnv { | ||
| name = "firewalld-paths"; | ||
| paths = cfg.packages; | ||
| pathsToLink = [ "/lib/firewalld" ]; | ||
| }; | ||
| in | ||
| { | ||
| imports = [ | ||
| ./service.nix | ||
| ./settings.nix | ||
| ./zone.nix | ||
| ]; | ||
Prince213 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| options.services.firewalld = { | ||
Prince213 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| enable = lib.mkEnableOption "FirewallD"; | ||
| package = lib.mkPackageOption pkgs "firewalld" { }; | ||
Prince213 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| packages = lib.mkOption { | ||
| type = lib.types.listOf lib.types.package; | ||
| default = [ ]; | ||
| description = '' | ||
| Packages providing firewalld zones and other files. | ||
| Files found in `/lib/firewalld` will be included. | ||
| ''; | ||
| }; | ||
| extraArgs = lib.mkOption { | ||
| type = lib.types.listOf lib.types.str; | ||
| default = [ ]; | ||
| example = [ "--debug" ]; | ||
| description = "Extra arguments to pass to FirewallD."; | ||
| }; | ||
| }; | ||
|
|
||
| config = lib.mkIf cfg.enable { | ||
| environment.systemPackages = [ cfg.package ]; | ||
| services.dbus.packages = [ cfg.package ]; | ||
| services.firewalld.packages = [ cfg.package ]; | ||
|
|
||
| services.logrotate.settings."/var/log/firewalld" = { | ||
| copytruncate = true; | ||
| minsize = "1M"; | ||
| }; | ||
|
|
||
| environment.etc."sysconfig/firewalld".text = '' | ||
| FIREWALLD_ARGS=${lib.concatStringsSep " " cfg.extraArgs} | ||
| ''; | ||
|
|
||
| systemd.packages = [ cfg.package ]; | ||
| systemd.services.firewalld = { | ||
| aliases = [ "dbus-org.fedoraproject.FirewallD1.service" ]; | ||
| wantedBy = [ "multi-user.target" ]; | ||
| serviceConfig.ExecReload = "${lib.getExe' pkgs.coreutils "kill"} -HUP $MAINPID"; | ||
| environment.NIX_FIREWALLD_CONFIG_PATH = "${paths}/lib/firewalld"; | ||
| }; | ||
| }; | ||
|
|
||
| meta.maintainers = with lib.maintainers; [ prince213 ]; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| { lib }: | ||
|
|
||
| let | ||
| inherit (lib) mkOption; | ||
| inherit (lib.types) | ||
| either | ||
| enum | ||
| nullOr | ||
| port | ||
| submodule | ||
| ; | ||
| mkPortOption = | ||
| { | ||
| optional ? false, | ||
| }: | ||
| mkOption { | ||
| type = | ||
| let | ||
| type = either port (submodule { | ||
Prince213 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| options = { | ||
| from = mkOption { type = port; }; | ||
| to = mkOption { type = port; }; | ||
| }; | ||
| }); | ||
| in | ||
| if optional then (nullOr type) else type; | ||
| description = ""; | ||
| apply = | ||
| value: if builtins.isAttrs value then "${toString value.from}-${toString value.to}" else value; | ||
Prince213 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
| protocolOption = mkOption { | ||
| type = enum [ | ||
| "tcp" | ||
| "udp" | ||
| "sctp" | ||
| "dccp" | ||
| ]; | ||
| description = ""; | ||
| }; | ||
| in | ||
| { | ||
| inherit mkPortOption; | ||
| inherit protocolOption; | ||
|
|
||
| toXmlAttrs = lib.mapAttrs' (name: lib.nameValuePair ("@" + name)); | ||
| mkXmlAttr = name: value: { "@${name}" = value; }; | ||
| filterNullAttrs = lib.filterAttrsRecursive (_: value: value != null); | ||
|
|
||
| portProtocolOptions = { | ||
| options = { | ||
| port = mkPortOption { }; | ||
| protocol = protocolOption; | ||
| }; | ||
| }; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.