48 lines
1.3 KiB
Nix
48 lines
1.3 KiB
Nix
{ self, nixpkgs, system }:
|
|
with nixpkgs.lib;
|
|
let
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
config = self.lib.config;
|
|
|
|
device-scripts =
|
|
builtins.mapAttrs (hostName: hostConfig@{ role, model, ... }:
|
|
pkgs.writeScriptBin "${hostName}.sh" (
|
|
let
|
|
args = {
|
|
inherit self hostName config hostConfig pkgs;
|
|
};
|
|
in {
|
|
ap = import ./ap.nix args;
|
|
switch = import (./switches + "/${model}.nix")
|
|
(args //
|
|
import ./switches/shared.nix args
|
|
);
|
|
}.${role}
|
|
)
|
|
) (
|
|
filterAttrs (_: { role, model, ... }:
|
|
role == "ap" ||
|
|
(role == "switch" && model != "dumb")
|
|
) 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}}/bin/${hostName}.sh $out/bin/${hostName}.sh"
|
|
) (builtins.attrNames device-scripts)
|
|
)
|
|
);
|
|
in
|
|
{
|
|
inherit all-device-scripts;
|
|
} // device-scripts
|