You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.1 KiB
69 lines
2.1 KiB
{ self, nixpkgs, system }: |
|
with nixpkgs.lib; |
|
let |
|
pkgs = nixpkgs.legacyPackages.${system}; |
|
config = self.lib.config; |
|
|
|
templates = role: { |
|
ap = _: ./ap.sh; |
|
switch = model: ../../salt/switches + "/${model}.expect"; |
|
}.${role}; |
|
replaceNetmasks = template: |
|
builtins.toFile (builtins.baseNameOf template) ( |
|
builtins.replaceStrings [''{%- import_yaml "netmasks.yaml" as netmasks -%}''] [""] ( |
|
builtins.readFile template |
|
) |
|
); |
|
expandTemplate = name: template: data: |
|
self.lib.expandSaltTemplate name (replaceNetmasks template) data; |
|
wrapNixShell = script: |
|
pkgs.runCommand (builtins.baseNameOf script) { |
|
src = script; |
|
} '' |
|
( |
|
echo '#! /usr/bin/env nix-shell' |
|
echo '#! nix-shell -i "expect -f" -p expect telnet' |
|
cat $src |
|
) > $out |
|
chmod a+x $out |
|
''; |
|
|
|
device-scripts = |
|
builtins.mapAttrs (hostname: { role, model, ... }: |
|
wrapNixShell ( |
|
expandTemplate "${hostname}.sh" (templates role model) ({ |
|
inherit hostname; |
|
pillar = config.salt-pillar; |
|
netmasks = self.lib.netmasks; |
|
logging = config.salt-pillar.hosts-inet.mgmt.logging; |
|
} // optionalAttrs (config.salt-pillar.switches ? ${hostname}) { |
|
switch = config.salt-pillar.switches.${hostname}; |
|
} // optionalAttrs (config.salt-pillar.cpe ? ${hostname}) { |
|
conf = config.salt-pillar.cpe.${hostname}; |
|
}) |
|
) |
|
) ( |
|
filterAttrs (_: { role, ... }: |
|
role == "ap" || role == "switch" |
|
) config.site.hosts |
|
); |
|
|
|
all-device-scripts = |
|
pkgs.runCommandLocal "all-device-scripts" {} ( |
|
'' |
|
mkdir -p $out/bin |
|
|
|
substitute ${./ap_install_collectd.sh} $out/bin/ap_install_collectd.sh \ |
|
--replace "{{STATS}}" "${config.site.net.serv.hosts6.dn42.stats}" |
|
chmod a+x $out/bin/ap_install_collectd.sh |
|
'' + |
|
builtins.concatStringsSep "\n" ( |
|
map (hostname: |
|
"ln -s ${device-scripts.${hostname}} $out/bin/${hostname}.sh" |
|
) (builtins.attrNames device-scripts) |
|
) |
|
); |
|
in |
|
{ |
|
inherit all-device-scripts; |
|
} // device-scripts
|
|
|