Netconf-Module/default.nix
2024-12-13 14:37:43 +01:00

76 lines
1.7 KiB
Nix

{
pkgs ? (import <nixpkgs> { }),
}:
let
lib = pkgs.lib;
hive_mod =
{
lib,
config,
name,
...
}:
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 = pkgs.writeText "config-${name}_rpc.xml" ''
<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}'';
};
};
};
evaluator =
name: module_inst:
let
cfg = pkgs.lib.evalModules {
specialArgs = {
inherit name;
};
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))