All checks were successful
CI / Format Check (push) Successful in 2s
CI / Flake Check (push) Successful in 1m44s
CI / Evaluate Key Configurations (nix-builder) (push) Successful in 14s
CI / Evaluate Key Configurations (nix-laptop1) (push) Successful in 8s
CI / Evaluate Artifacts (lxc-nix-builder) (push) Successful in 13s
CI / Build and Publish Documentation (push) Successful in 10s
CI / Evaluate Key Configurations (nix-desktop1) (push) Successful in 8s
CI / Evaluate Artifacts (installer-iso-nix-laptop1) (push) Successful in 19s
34 lines
1.0 KiB
Nix
34 lines
1.0 KiB
Nix
{ lib }:
|
|
let
|
|
# Default MAC address to station number mapping
|
|
defaultHostmap = {
|
|
"00:e0:4c:46:0b:32" = "1";
|
|
"00:e0:4c:46:07:26" = "2";
|
|
"00:e0:4c:46:05:94" = "3";
|
|
"00:e0:4c:46:07:11" = "4";
|
|
"00:e0:4c:46:08:02" = "5";
|
|
"00:e0:4c:46:08:5c" = "6";
|
|
};
|
|
|
|
# macCaseBuilder: builds a shell case statement from a hostmap
|
|
# Parameters:
|
|
# varName: the shell variable to assign
|
|
# prefix: optional string to prepend to the value (default: "")
|
|
# hostmap: optional attribute set to use (default: built-in hostmap)
|
|
#
|
|
# Example:
|
|
# macCaseBuilder { varName = "STATION"; prefix = "nix-"; }
|
|
# # Generates case statements like: 00:e0:4c:46:0b:32) STATION=nix-1 ;;
|
|
builder =
|
|
{
|
|
varName,
|
|
prefix ? "",
|
|
hostmap ? defaultHostmap,
|
|
}:
|
|
lib.concatStringsSep "\n" (
|
|
lib.mapAttrsToList (mac: val: " ${mac}) ${varName}=${prefix}${val} ;;") hostmap
|
|
);
|
|
in
|
|
# Export the builder function with hostmap as an accessible attribute
|
|
lib.setFunctionArgs builder { } // { hostmap = defaultHostmap; }
|