network/nix/pkgs/device-templates.nix

48 lines
1.3 KiB
Nix
Raw Normal View History

2022-05-27 01:37:03 +02:00
{ self, nixpkgs, system, openwrt }:
2021-03-19 01:41:12 +01:00
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 {
2022-05-27 01:37:03 +02:00
ap = openwrt.sshScript hostName;
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}
)
) (
2022-02-05 00:33:09 +01:00
filterAttrs (_: { role, model, ... }:
role == "ap" ||
(role == "switch" && model != "dumb")
) 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