2024-04-28 11:47:10 +02:00
|
|
|
{
|
|
|
|
pkgs ? (import <nixpkgs> { }),
|
|
|
|
}:
|
2024-04-06 23:11:39 +02:00
|
|
|
let
|
2024-04-30 20:08:07 +02:00
|
|
|
lib = pkgs.lib;
|
2024-05-22 13:33:28 +02:00
|
|
|
hive_mod =
|
|
|
|
{
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
name,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib;
|
|
|
|
{
|
|
|
|
options.deployment = {
|
|
|
|
targetHost = mkOption { type = types.str; };
|
|
|
|
rpc = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
readOnly = true;
|
|
|
|
};
|
|
|
|
cmd = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
readOnly = true;
|
|
|
|
};
|
2024-04-30 20:08:07 +02:00
|
|
|
};
|
2024-05-22 13:33:28 +02:00
|
|
|
config.deployment = rec {
|
|
|
|
rpc = pkgs.writeText "config-${name}_rpc.xml" ''
|
2024-04-30 20:08:07 +02:00
|
|
|
<rpc>
|
|
|
|
<edit-config>
|
|
|
|
<config>
|
|
|
|
${config.netconf.xmls.configuration}
|
|
|
|
</config>
|
|
|
|
<target>
|
|
|
|
<candidate/>
|
|
|
|
</target>
|
|
|
|
</edit-config>
|
|
|
|
</rpc>
|
|
|
|
<rpc>
|
|
|
|
<commit/>
|
|
|
|
</rpc>
|
|
|
|
'';
|
|
|
|
cmd = pkgs.writeShellApplication {
|
|
|
|
name = "deploy-${name}.sh";
|
|
|
|
runtimeInputs = with pkgs; [ openssh ];
|
|
|
|
text = ''ssh "${config.deployment.targetHost}" -p 830 -s netconf < ${rpc}'';
|
|
|
|
};
|
|
|
|
};
|
2024-05-22 13:33:28 +02:00
|
|
|
};
|
2024-04-28 11:47:10 +02:00
|
|
|
evaluator =
|
|
|
|
name: module_inst:
|
|
|
|
let
|
|
|
|
cfg = pkgs.lib.evalModules {
|
|
|
|
specialArgs = {
|
2024-04-30 20:08:07 +02:00
|
|
|
inherit name;
|
2024-04-28 11:47:10 +02:00
|
|
|
};
|
|
|
|
modules = [
|
2024-04-30 20:08:07 +02:00
|
|
|
./junos
|
|
|
|
./ex2300.nix
|
|
|
|
hive_mod
|
2024-04-28 11:47:10 +02:00
|
|
|
module_inst
|
|
|
|
];
|
|
|
|
};
|
|
|
|
in
|
2024-04-30 20:08:07 +02:00
|
|
|
"ln -s ${lib.getExe cfg.config.deployment.cmd} $out/${name}";
|
2024-04-06 23:11:39 +02:00
|
|
|
hive = import ./netconf-hive.nix;
|
|
|
|
cmds = builtins.attrValues (builtins.mapAttrs evaluator hive);
|
|
|
|
in
|
2024-04-28 11:47:10 +02:00
|
|
|
pkgs.runCommand "netconf-deploy" { } (builtins.concatStringsSep "\n" ([ "mkdir $out" ] ++ cmds))
|