From ce49c22d2e0883257cc7fa9ddfeb83f46697d2e9 Mon Sep 17 00:00:00 2001 From: Astro Date: Thu, 29 Apr 2021 01:39:21 +0200 Subject: [PATCH] pkgs/device-templates: make executable and wrap scripts --- nix/pkgs/device-templates.nix | 42 ++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/nix/pkgs/device-templates.nix b/nix/pkgs/device-templates.nix index 58136ce..9c22549 100644 --- a/nix/pkgs/device-templates.nix +++ b/nix/pkgs/device-templates.nix @@ -16,22 +16,37 @@ 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, ... }: - 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); + 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" {} ( @@ -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: