~dblsaiko/nix-extras

2eaf79c831487132ecadf03f9810408c2557639f — Marco Rebhan 3 months ago 11f2c8a
nixos/nftables: Fold params list instead of getting items by index
1 files changed, 8 insertions(+), 10 deletions(-)

M nixos/ext/networking/nftables/expressions.nix
M nixos/ext/networking/nftables/expressions.nix => nixos/ext/networking/nftables/expressions.nix +8 -10
@@ 1,18 1,16 @@
{lib, ...}: let
  inherit (lib) concatStringsSep elemAt filter foldl length mapAttrs mapAttrsToList mkMerge mkOption optional optionalAttrs;
  inherit (lib) concatStringsSep filter foldl id length mapAttrs mapAttrsToList mkMerge mkOption optional;
  inherit (lib.types) attrsOf enum int listOf nonEmptyListOf nullOr oneOf str submodule;
  inherit (import ./lib.nix lib) flatMap flatMapAttrsToList formatList;
  inherit (import ./types.nix lib) arp_op bitmask boolean cgroupv2 ct_dir ct_id ct_label ct_state ct_status dccp_pkttype devgroup dscp ecn ether_addr ether_type exprElemType fib_addrtype gid icmp_type icmpv6_type iface_index iface_type ifname igmp_type inet_proto inet_service ip_addr ipv4_addr ipv6_addr l4proto mark nf_proto pkt_type realm tc_handle tcp_flag time u1 u3 u4 u8 u12 u16 u20 u32 u64 uid;

  fromParams = desc:
    {
      keyword = elemAt desc 0;
      description = elemAt desc 1;
      type = elemAt desc 2;
    }
    // optionalAttrs (length desc > 3) {
      extraOptions = elemAt desc 3;
    };
  fromParams = desc: let
    constructor =
      if length desc <= 3
      then keyword: description: type: {inherit keyword description type;}
      else keyword: description: type: extraOptions: {inherit keyword description type extraOptions;};
  in
    foldl id constructor desc;

  fromTable = foldl (acc: a: let
    attrs = fromParams a;