network/nix/pkgs/device-templates.nix

47 lines
1.3 KiB
Nix
Raw Normal View History

2021-03-19 01:41:12 +01:00
{ self, nixpkgs, system }:
with nixpkgs.lib;
2021-02-25 01:06:32 +01:00
let
2021-03-19 01:41:12 +01:00
pkgs = nixpkgs.legacyPackages.${system};
config = self.lib.config;
2021-03-19 01:41:12 +01:00
device-scripts =
2021-11-03 01:07:44 +01:00
builtins.mapAttrs (hostName: hostConfig@{ role, model, ... }:
pkgs.writeScriptBin "${hostName}.sh" (
2021-11-03 01:07:44 +01:00
let
args = {
2021-11-07 02:22:24 +01:00
inherit self hostName config hostConfig pkgs;
2021-11-03 01:07:44 +01:00
};
in {
ap = import ./ap.nix args;
2021-11-07 02:22:24 +01:00
switch = import (./switches + "/${model}.nix")
(args //
import ./switches/shared.nix args
);
2021-11-03 01:07:44 +01:00
}.${role}
)
) (
filterAttrs (_: { role, ... }:
role == "ap" || role == "switch"
) config.site.hosts
);
2021-02-25 01:06:32 +01:00
2021-03-19 01:41:12 +01:00
all-device-scripts =
2021-02-25 01:06:32 +01:00
pkgs.runCommandLocal "all-device-scripts" {} (
''
mkdir -p $out/bin
2021-04-25 23:53:38 +02:00
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
2021-02-25 01:06:32 +01:00
'' +
builtins.concatStringsSep "\n" (
2021-11-03 01:07:44 +01:00
map (hostName:
"ln -s ${device-scripts.${hostName}}/bin/${hostName}.sh $out/bin/${hostName}.sh"
) (builtins.attrNames device-scripts)
2021-02-25 01:06:32 +01:00
)
);
2021-03-19 01:41:12 +01:00
in
{
inherit all-device-scripts;
} // device-scripts