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,
|
|
|
|
...
|
|
|
|
}:
|
2024-12-13 14:37:43 +01:00
|
|
|
let
|
|
|
|
inherit (lib)
|
|
|
|
mkOption
|
|
|
|
;
|
|
|
|
inherit (lib.types)
|
|
|
|
str
|
|
|
|
package
|
|
|
|
;
|
|
|
|
in
|
2024-05-22 13:33:28 +02:00
|
|
|
{
|
|
|
|
options.deployment = {
|
2024-12-13 14:37:43 +01:00
|
|
|
targetHost = mkOption { type = str; };
|
2024-05-22 13:33:28 +02:00
|
|
|
rpc = mkOption {
|
2024-12-13 14:37:43 +01:00
|
|
|
type = package;
|
2024-05-22 13:33:28 +02:00
|
|
|
readOnly = true;
|
|
|
|
};
|
|
|
|
cmd = mkOption {
|
2024-12-13 14:37:43 +01:00
|
|
|
type = package;
|
2024-05-22 13:33:28 +02:00
|
|
|
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
|
2024-09-03 23:38:29 +02:00
|
|
|
./dgn-module.nix
|
2024-04-30 20:08:07 +02:00
|
|
|
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))
|