From b791058a88e1348df9705e82472d7f37c8791cdb Mon Sep 17 00:00:00 2001 From: catvayor Date: Fri, 13 Dec 2024 14:37:43 +0100 Subject: [PATCH] chore: remove `with lib;` --- default.nix | 16 +++++++++++---- dgn-module.nix | 41 +++++++++++++++++++++++++----------- junos/default.nix | 17 +++++++++++---- junos/interfaces.nix | 46 ++++++++++++++++++++++++++--------------- junos/poe.nix | 23 ++++++++++++++------- junos/protocols.nix | 15 +++++++++++--- junos/system.nix | 30 ++++++++++++++++++++------- junos/vlans.nix | 49 ++++++++++++++++++++++++++++++++------------ 8 files changed, 171 insertions(+), 66 deletions(-) diff --git a/default.nix b/default.nix index 61bd20a..cb246cc 100644 --- a/default.nix +++ b/default.nix @@ -10,16 +10,24 @@ let name, ... }: - with lib; + let + inherit (lib) + mkOption + ; + inherit (lib.types) + str + package + ; + in { options.deployment = { - targetHost = mkOption { type = types.str; }; + targetHost = mkOption { type = str; }; rpc = mkOption { - type = types.package; + type = package; readOnly = true; }; cmd = mkOption { - type = types.package; + type = package; readOnly = true; }; }; diff --git a/dgn-module.nix b/dgn-module.nix index e20af33..7922f4c 100644 --- a/dgn-module.nix +++ b/dgn-module.nix @@ -1,6 +1,23 @@ { config, lib, ... }: -with lib; let + inherit (lib) + mkEnableOption + mkOption + filterAttrs + mapAttrs + attrNames + mkIf + ; + inherit (lib.types) + nullOr + enum + listOf + either + str + ints + attrsOf + submodule + ; intf-mod = { config, ... }: { @@ -20,12 +37,10 @@ let defaultText = ''config.ethernet-switching.enable''; }; interface-mode = mkOption { - type = types.nullOr ( - types.enum [ - "trunk" - "access" - ] - ); + type = nullOr (enum [ + "trunk" + "access" + ]); default = null; description = '' Mode of operation for vlan addressing of this interface. @@ -35,7 +50,7 @@ let ''; }; vlans = mkOption { - type = types.listOf (types.either types.str types.ints.unsigned); + type = listOf (either str ints.unsigned); default = [ ]; description = '' Vlans that can be used on this interface. @@ -49,7 +64,7 @@ let defaultText = ''config.inet.addresses != [ ]''; }; addresses = mkOption { - type = types.listOf types.str; + type = listOf str; default = [ ]; description = '' ipv4 addresses of this interface. @@ -62,7 +77,7 @@ let defaultText = ''config.inet6.addresses != [ ]''; }; addresses = mkOption { - type = types.listOf types.str; + type = listOf str; default = [ ]; description = '' ipv6 addresses of this interface. @@ -76,7 +91,7 @@ let in { options.dgn-interfaces = mkOption { - type = types.attrsOf (types.submodule intf-mod); + type = attrsOf (submodule intf-mod); default = { }; description = '' Unified configuration of interfaces adapted to DGNum usage: @@ -91,7 +106,9 @@ in inherit (intf) enable; unit."0".family = { inherit (intf) inet inet6; - ethernet-switching = mkIf intf.ethernet-switching.enable (removeAttrs intf.ethernet-switching [ "rstp" ]); + ethernet-switching = mkIf intf.ethernet-switching.enable ( + removeAttrs intf.ethernet-switching [ "rstp" ] + ); }; }) cfg; poe.interfaces = filterAttrs ( diff --git a/junos/default.nix b/junos/default.nix index 78107a0..a00e805 100644 --- a/junos/default.nix +++ b/junos/default.nix @@ -3,11 +3,20 @@ config, ... }: -with lib; let + inherit (lib) + mkOption + mapAttrs + ; + inherit (lib.types) + bool + str + attrsOf + submodule + ; mandatory.options = { supportPoE = mkOption { - type = types.bool; + type = bool; example = true; description = '' Wether this interface supports PoE. @@ -25,14 +34,14 @@ in ]; options = { netconf.xmls.configuration = mkOption { - type = types.str; + type = str; readOnly = true; description = '' The full configuration to send to a JunOS. ''; }; netconf.mandatoryInterfaces = mkOption { - type = types.attrsOf (types.submodule mandatory); + type = attrsOf (submodule mandatory); example = { "ge-0/0/0" = { supportPoE = true; diff --git a/junos/interfaces.nix b/junos/interfaces.nix index b83d636..31ddc72 100644 --- a/junos/interfaces.nix +++ b/junos/interfaces.nix @@ -1,6 +1,21 @@ { lib, config, ... }: -with lib; let + inherit (lib) + mkEnableOption + mkOption + optionalString + mapAttrsToList + ; + inherit (lib.types) + enum + listOf + either + str + ints + submodule + attrsOf + ; + interface = { name, config, ... }: let @@ -17,11 +32,10 @@ let ethernet-switching = { enable = mkEnableOption "the ethernet switching on this logical interface"; interface-mode = mkOption { - type = - types.enum [ - "trunk" - "access" - ]; + type = enum [ + "trunk" + "access" + ]; description = '' Mode of operation for vlan addressing of this interface. "trunk" means that the traffic is tagged, "access" means the @@ -29,7 +43,7 @@ let ''; }; vlans = mkOption { - type = types.listOf (types.either types.str types.ints.unsigned); + type = listOf (either str ints.unsigned); default = [ ]; description = '' Vlans that can be used on this interface. @@ -41,7 +55,7 @@ let inet = { enable = mkEnableOption "the IPv4 configuration of this logical interface"; addresses = mkOption { - type = types.listOf types.str; + type = listOf str; default = [ ]; description = '' ipv4 addresses of this interface. @@ -51,7 +65,7 @@ let inet6 = { enable = mkEnableOption "the IPv6 configuration of this logical interface"; addresses = mkOption { - type = types.listOf types.str; + type = listOf str; default = [ ]; description = '' ipv6 addresses of this interface. @@ -60,7 +74,7 @@ let }; }; xml = mkOption { - type = types.str; + type = str; visible = false; readOnly = true; }; @@ -106,21 +120,21 @@ let options = { enable = mkEnableOption "this physical interface"; unit = mkOption { - type = types.attrsOf (types.submodule unit); + type = attrsOf (submodule unit); default = { }; description = '' Configuration of the logical interfaces on this physical interface. ''; }; xml = mkOption { - type = types.str; + type = str; visible = false; readOnly = true; }; }; config.xml = let - units = attrsets.mapAttrsToList (_: unit: unit.xml) config.unit; + units = mapAttrsToList (_: unit: unit.xml) config.unit; in '' @@ -134,20 +148,20 @@ in { options = { interfaces = mkOption { - type = types.attrsOf (types.submodule interface); + type = attrsOf (submodule interface); description = '' The interfaces configuration. ''; }; netconf.xmls.interfaces = mkOption { - type = types.str; + type = str; visible = false; readOnly = true; }; }; config.netconf.xmls.interfaces = '' - ${builtins.concatStringsSep "" (attrsets.mapAttrsToList (_: intf: intf.xml) config.interfaces)} + ${builtins.concatStringsSep "" (mapAttrsToList (_: intf: intf.xml) config.interfaces)} ''; } diff --git a/junos/poe.nix b/junos/poe.nix index fc06479..36124dd 100644 --- a/junos/poe.nix +++ b/junos/poe.nix @@ -1,13 +1,24 @@ { lib, config, ... }: -with lib; let + inherit (lib) + mkOption + mkEnableOption + mapAttrsToList + optionalString + ; + inherit (lib.types) + str + attrsOf + submodule + ; + interface-module = { name, config, ... }: { options = { enable = mkEnableOption "the PoE for this interface"; xml = mkOption { - type = types.str; + type = str; visible = false; readOnly = true; }; @@ -20,23 +31,21 @@ in { options = { poe.interfaces = mkOption { - type = types.attrsOf (types.submodule interface-module); + type = attrsOf (submodule interface-module); default = { }; description = '' PoE configuration of interfaces. ''; }; netconf.xmls.poe = mkOption { - type = types.str; + type = str; visible = false; readOnly = true; }; }; config.netconf.xmls.poe = '' - ${ - builtins.concatStringsSep "" (attrsets.mapAttrsToList (_: intf: intf.xml) config.poe.interfaces) - } + ${builtins.concatStringsSep "" (mapAttrsToList (_: intf: intf.xml) config.poe.interfaces)} ''; } diff --git a/junos/protocols.nix b/junos/protocols.nix index e6535ec..33e82fd 100644 --- a/junos/protocols.nix +++ b/junos/protocols.nix @@ -1,15 +1,24 @@ { lib, config, ... }: -with lib; +let + inherit (lib) + mkOption + concatStringsSep + ; + inherit (lib.types) + listOf + str + ; +in { options = { protocols.rstp = mkOption { - type = types.listOf types.str; + type = listOf str; description = '' List of interfaces on which Rapid Spanning Tree Protocol should be enabled. ''; }; netconf.xmls.protocols = mkOption { - type = types.str; + type = str; visible = false; readOnly = true; }; diff --git a/junos/system.nix b/junos/system.nix index 8868131..492f243 100644 --- a/junos/system.nix +++ b/junos/system.nix @@ -1,26 +1,42 @@ { lib, config, ... }: -with lib; +let + inherit (lib) + mkOption + splitString + length + hasPrefix + filter + concatStrings + concatStringsSep + ; + inherit (lib.types) + str + listOf + enum + port + ; +in { options = { system = { host-name = mkOption { - type = types.str; + type = str; description = "The hostname of the switch."; }; root-authentication = { hashedPasswd = mkOption { - type = types.str; + type = str; description = "Hashed password for root."; }; ssh-keys = mkOption { - type = types.listOf types.str; + type = listOf str; description = "ssh keys for root user."; default = [ ]; }; }; services = { ssh.root-login = mkOption { - type = types.enum [ + type = enum [ "allow" "deny" "deny-password" @@ -28,14 +44,14 @@ with lib; description = "Login policy to use for root."; }; netconf.port = mkOption { - type = types.port; + type = port; description = "Port to use for netconf."; default = 830; }; }; }; netconf.xmls.system = mkOption { - type = types.str; + type = str; visible = false; readOnly = true; }; diff --git a/junos/vlans.nix b/junos/vlans.nix index 40a0eee..a129cc4 100644 --- a/junos/vlans.nix +++ b/junos/vlans.nix @@ -1,12 +1,29 @@ { lib, config, ... }: -with lib; let + inherit (lib) + mkOption + optionalString + assertMsg + concatStringsSep + mapAttrsToList + ; + inherit (lib.types) + nullOr + ints + unspecified + listOf + either + submodule + str + attrsOf + ; + vlan = { name, config, ... }: { options = { id = mkOption { - type = types.nullOr types.ints.unsigned; + type = nullOr ints.unsigned; default = null; description = '' The ID of this vlan, `null` means no ID. @@ -22,27 +39,30 @@ let config.__toString = _: "${toString config.begin}-${toString config.end}"; options = { begin = mkOption { - type = types.ints.unsigned; + type = ints.unsigned; visible = false; }; end = mkOption { - type = types.ints.unsigned; + type = ints.unsigned; visible = false; }; __toString = mkOption { visible = false; internal = true; readOnly = true; - type = types.unspecified; + type = unspecified; }; }; }; in - types.listOf (types.either types.ints.unsigned (types.submodule range_type)); + listOf (either ints.unsigned (submodule range_type)); default = [ ]; example = [ 42 - { begin = 100; end = 200; } + { + begin = 100; + end = 200; + } ]; description = '' List of IDs or IDs range to classify as this vlan. @@ -50,7 +70,7 @@ let ''; }; l3-interface = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = null; example = "irb.0"; description = '' @@ -60,7 +80,7 @@ let ''; }; xml = mkOption { - type = types.str; + type = str; readOnly = true; visible = false; }; @@ -75,7 +95,10 @@ let !isNull config.l3-interface ) "${config.l3-interface}"; in - assert assertMsg (config.id == null || config.id-list == [ ]) "vlans.${name}.id and vlans.${name}.id-list are incompatible."; '' + assert assertMsg ( + config.id == null || config.id-list == [ ] + ) "vlans.${name}.id and vlans.${name}.id-list are incompatible."; + '' ${name} ${id}${id-list}${l3-intf} @@ -86,21 +109,21 @@ in { options = { vlans = mkOption { - type = types.attrsOf (types.submodule vlan); + type = attrsOf (submodule vlan); description = '' Named vlans configuration. Allows to name vlans inside interface configuration, instead of just using their IDs. ''; }; netconf.xmls.vlans = mkOption { - type = types.str; + type = str; visible = false; readOnly = true; }; }; config.netconf.xmls.vlans = '' - ${builtins.concatStringsSep "" (attrsets.mapAttrsToList (_: vlan: vlan.xml) config.vlans)} + ${builtins.concatStringsSep "" (mapAttrsToList (_: vlan: vlan.xml) config.vlans)} ''; }