let sources = import ./npins; pkgs = import sources.kat-pkgs { }; lib = pkgs.lib; hive_mod = { lib, config, name, xml, ... }: let inherit (lib) mkOption ; inherit (lib.types) str package ; in { options.deployment = { targetHost = mkOption { type = str; }; rpc = mkOption { type = package; readOnly = true; }; cmd = mkOption { type = package; readOnly = true; }; }; config.deployment = rec { rpc = xml.generate "config-${name}_rpc.xml" { rpc = [ { edit-config = { config.configuration = config.netconf.xml; target.candidate = ""; }; } { commit = { }; } ]; }; cmd = pkgs.writeShellApplication { name = "deploy-${name}.sh"; runtimeInputs = with pkgs; [ openssh ]; text = ''ssh "${config.deployment.targetHost}" -p 830 -s netconf < ${rpc}''; }; }; }; evaluator = name: module_inst: let cfg = pkgs.lib.evalModules { specialArgs = { inherit name; xml = pkgs.formats.xml { }; }; modules = [ ./junos ./dgn-module.nix hive_mod module_inst ]; }; in "ln -s ${lib.getExe cfg.config.deployment.cmd} $out/${name}"; hive = import ./netconf-hive.nix; cmds = builtins.attrValues (builtins.mapAttrs evaluator hive); in pkgs.runCommand "netconf-deploy" { } (builtins.concatStringsSep "\n" ([ "mkdir $out" ] ++ cmds))