From e8cdd067065944cdda5f02d6547a08007cc64f2b Mon Sep 17 00:00:00 2001 From: catvayor Date: Sun, 15 Dec 2024 20:40:51 +0100 Subject: [PATCH] feat(netconf): toplevel rpc drv --- hive.nix | 5 +- lib/netconf-junos/default.nix | 108 ++++++++++++++++++++++------------ 2 files changed, 74 insertions(+), 39 deletions(-) diff --git a/hive.nix b/hive.nix index 60716f6..707fcd5 100644 --- a/hive.nix +++ b/hive.nix @@ -126,11 +126,14 @@ in }; netconf = { - evalConfig = (import nixpkgs.nixos.unstable.path { }).lib.evalModules; + evalConfig = nixpkgs.nixos.unstable.lib.evalModules; defaults = { nodeMeta, nodePath, ... }: { + _module.args = { + pkgs = nixpkgs.nixos.unstable; + }; # Import the default modules imports = [ # Import the base configuration for each node diff --git a/lib/netconf-junos/default.nix b/lib/netconf-junos/default.nix index 70ac56d..a0dfd8f 100644 --- a/lib/netconf-junos/default.nix +++ b/lib/netconf-junos/default.nix @@ -1,4 +1,10 @@ -{ config, lib, ... }: +{ + config, + lib, + pkgs, + name, + ... +}: let inherit (lib) mapAttrs mkOption; @@ -9,6 +15,7 @@ let str any submodule + package ; mandatory.options = { @@ -36,45 +43,70 @@ in type = attrsOf any; default = { }; }; - netconf.xmls.configuration = mkOption { - type = str; - readOnly = true; - description = '' - The full configuration to send to a JunOS. - ''; - }; - netconf.mandatoryInterfaces = mkOption { - type = attrsOf (submodule mandatory); - example = { - "ge-0/0/0" = { - supportPoE = true; - }; - "ge-0/0/1" = { - supportPoE = true; - }; - "xe-0/0/0" = { - supportPoE = false; - }; + netconf = { + xmls.configuration = mkOption { + type = str; + readOnly = true; + description = '' + The full configuration to send to a JunOS. + ''; }; - description = '' - JunOS require some interfaces to always be configured (even if they are disabled), - which correspond to physical interfaces of the switch. They have to be declared here - with some information about it (only if it supports PoE for now). + mandatoryInterfaces = mkOption { + type = attrsOf (submodule mandatory); + example = { + "ge-0/0/0" = { + supportPoE = true; + }; + "ge-0/0/1" = { + supportPoE = true; + }; + "xe-0/0/0" = { + supportPoE = false; + }; + }; + description = '' + JunOS require some interfaces to always be configured (even if they are disabled), + which correspond to physical interfaces of the switch. They have to be declared here + with some information about it (only if it supports PoE for now). + ''; + }; + rpc = mkOption { + type = package; + readOnly = true; + }; + }; + }; + config = { + interfaces = + let + mkIntf = _: _: { }; + in + mapAttrs mkIntf config.netconf.mandatoryInterfaces; + netconf = { + xmls.configuration = with config.netconf.xmls; '' + + ${system} + ${interfaces} + ${protocols} + ${vlans} + ${poe} + + ''; + rpc = pkgs.writeText "${name}.rpc" '' + + + + ${config.netconf.xmls.configuration} + + + + + + + + + ''; }; }; - config.interfaces = - let - mkIntf = _: _: { }; - in - mapAttrs mkIntf config.netconf.mandatoryInterfaces; - config.netconf.xmls.configuration = with config.netconf.xmls; '' - - ${system} - ${interfaces} - ${protocols} - ${vlans} - ${poe} - - ''; }