pkgs/device-templates: make executable and wrap scripts

This commit is contained in:
Astro 2021-04-29 01:39:21 +02:00
parent 02de036ba7
commit ce49c22d2e
1 changed files with 29 additions and 13 deletions

View File

@ -16,22 +16,37 @@ let
); );
expandTemplate = name: template: data: expandTemplate = name: template: data:
self.lib.expandSaltTemplate name (replaceNetmasks 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 = device-scripts =
builtins.mapAttrs (hostname: { role, model, ... }: builtins.mapAttrs (hostname: { role, model, ... }:
expandTemplate "${hostname}.sh" (templates role model) ({ wrapNixShell (
inherit hostname; expandTemplate "${hostname}.sh" (templates role model) ({
pillar = config.salt-pillar; inherit hostname;
netmasks = self.lib.netmasks; pillar = config.salt-pillar;
logging = config.salt-pillar.hosts-inet.mgmt.logging; netmasks = self.lib.netmasks;
} // optionalAttrs (config.salt-pillar.switches ? ${hostname}) { logging = config.salt-pillar.hosts-inet.mgmt.logging;
switch = config.salt-pillar.switches.${hostname}; } // optionalAttrs (config.salt-pillar.switches ? ${hostname}) {
} // optionalAttrs (config.salt-pillar.cpe ? ${hostname}) { switch = config.salt-pillar.switches.${hostname};
conf = config.salt-pillar.cpe.${hostname}; } // optionalAttrs (config.salt-pillar.cpe ? ${hostname}) {
}) conf = config.salt-pillar.cpe.${hostname};
) (filterAttrs (_: { role, ... }: })
role == "ap" || role == "switch" )
) config.site.hosts); ) (
filterAttrs (_: { role, ... }:
role == "ap" || role == "switch"
) config.site.hosts
);
all-device-scripts = all-device-scripts =
pkgs.runCommandLocal "all-device-scripts" {} ( pkgs.runCommandLocal "all-device-scripts" {} (
@ -40,6 +55,7 @@ let
substitute ${./ap_install_collectd.sh} $out/bin/ap_install_collectd.sh \ substitute ${./ap_install_collectd.sh} $out/bin/ap_install_collectd.sh \
--replace "{{STATS}}" "${config.site.net.serv.hosts6.dn42.stats}" --replace "{{STATS}}" "${config.site.net.serv.hosts6.dn42.stats}"
chmod a+x $out/bin/ap_install_collectd.sh
'' + '' +
builtins.concatStringsSep "\n" ( builtins.concatStringsSep "\n" (
map (hostname: map (hostname: