refactor(flake): split assembly by concept

This commit is contained in:
2026-08-29 17:05:43 -04:00
parent 6f0f586fb6
commit 647b20b934
14 changed files with 149 additions and 97 deletions

9
lib/default.nix Normal file
View File

@@ -0,0 +1,9 @@
{ lib }:
let
files = import ./files.nix { inherit lib; };
network = import ./network.nix { inherit lib; };
in
{
inherit (files) collectNixFiles;
inherit (network) bridgeName deriveMac;
}

22
lib/files.nix Normal file
View File

@@ -0,0 +1,22 @@
{ lib }:
let
collectNixFiles =
dir:
lib.flatten (
lib.mapAttrsToList (
name: type:
let
path = dir + "/${name}";
in
if type == "directory" then
collectNixFiles path
else if type == "regular" && lib.hasSuffix ".nix" name then
[ path ]
else
[ ]
) (builtins.readDir dir)
);
in
{
inherit collectNixFiles;
}

12
lib/network.nix Normal file
View File

@@ -0,0 +1,12 @@
{ lib }:
{
bridgeName = id: "br-vlan${toString id}";
deriveMac =
name:
let
hash = builtins.hashString "sha256" name;
octet = i: builtins.substring (i * 2) 2 hash;
in
lib.concatStringsSep ":" ([ "02" ] ++ map octet [ 0 1 2 3 4 ]);
}