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,9 +16,21 @@ let
);
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;
@ -29,9 +41,12 @@ let
} // optionalAttrs (config.salt-pillar.cpe ? ${hostname}) {
conf = config.salt-pillar.cpe.${hostname};
})
) (filterAttrs (_: { role, ... }:
)
) (
filterAttrs (_: { role, ... }:
role == "ap" || role == "switch"
) config.site.hosts);
) config.site.hosts
);
all-device-scripts =
pkgs.runCommandLocal "all-device-scripts" {} (
@ -40,6 +55,7 @@ let
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: