mirror of
https://github.com/oddlama/nix-config.git
synced 2025-10-10 23:00:39 +02:00
chore: PoC to generate d2 network graph
This commit is contained in:
parent
e1231f8da1
commit
490e2ce1a5
3 changed files with 99 additions and 0 deletions
12
flake.nix
12
flake.nix
|
@ -152,6 +152,18 @@
|
||||||
nixosConfigurationsMinimal
|
nixosConfigurationsMinimal
|
||||||
;
|
;
|
||||||
|
|
||||||
|
# XXX: WIP: only testing
|
||||||
|
d2diag = let
|
||||||
|
inherit
|
||||||
|
(nixpkgs.lib)
|
||||||
|
attrValues
|
||||||
|
concatLines
|
||||||
|
;
|
||||||
|
in
|
||||||
|
self.pkgs.x86_64-linux.writeText "test.d2" (
|
||||||
|
concatLines (map (x: x.config.d2diag.text) (attrValues self.nixosConfigurations))
|
||||||
|
);
|
||||||
|
|
||||||
# All nixosSystem instanciations are collected here, so that we can refer
|
# All nixosSystem instanciations are collected here, so that we can refer
|
||||||
# to any system via nodes.<name>
|
# to any system via nodes.<name>
|
||||||
nodes = self.nixosConfigurations // self.guestConfigs;
|
nodes = self.nixosConfigurations // self.guestConfigs;
|
||||||
|
|
85
modules/d2diag.nix
Normal file
85
modules/d2diag.nix
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
nodes,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
inherit
|
||||||
|
(lib)
|
||||||
|
attrNames
|
||||||
|
concatMap
|
||||||
|
getAttrFromPath
|
||||||
|
mkMerge
|
||||||
|
mkOption
|
||||||
|
optionals
|
||||||
|
types
|
||||||
|
;
|
||||||
|
|
||||||
|
nodeName = config.node.name;
|
||||||
|
in {
|
||||||
|
options.d2diag.text = mkOption {
|
||||||
|
# TODO readonly, _text
|
||||||
|
description = "TODO";
|
||||||
|
type = types.lines;
|
||||||
|
};
|
||||||
|
|
||||||
|
options.d2diag.services = mkOption {
|
||||||
|
description = "TODO";
|
||||||
|
type = types.attrsOf (types.submodule {
|
||||||
|
options = {
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
d2diag.text =
|
||||||
|
''
|
||||||
|
${nodeName}: ${nodeName} {
|
||||||
|
disks: Disks {
|
||||||
|
shape: sql_table
|
||||||
|
${lib.concatLines (map (x: "${x}: 8TB") (lib.attrNames config.disko.devices.disk))}
|
||||||
|
}
|
||||||
|
net: Interfaces {
|
||||||
|
shape: sql_table
|
||||||
|
${lib.concatLines (lib.mapAttrsToList (n: v: ''${n}: ${v.mac}'') (config.repo.secrets.local.networking.interfaces or {lan.mac = "?";}))}
|
||||||
|
}
|
||||||
|
''
|
||||||
|
+ (lib.optionalString (config.guests != {}) ''
|
||||||
|
guests: {
|
||||||
|
${
|
||||||
|
lib.concatLines (
|
||||||
|
lib.flip lib.mapAttrsToList config.guests (
|
||||||
|
guestName: guestDef:
|
||||||
|
(
|
||||||
|
if guestDef.backend == "microvm"
|
||||||
|
then config.microvm.vms.${guestName}.config
|
||||||
|
else config.containers.${guestName}.nixosConfiguration
|
||||||
|
)
|
||||||
|
.config
|
||||||
|
.d2diag
|
||||||
|
.text
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
${
|
||||||
|
lib.concatLines (
|
||||||
|
lib.flip lib.mapAttrsToList config.guests (
|
||||||
|
guestName: guestDef: "net.lan -> guests.${(
|
||||||
|
if guestDef.backend == "microvm"
|
||||||
|
then config.microvm.vms.${guestName}.config
|
||||||
|
else config.containers.${guestName}.nixosConfiguration
|
||||||
|
)
|
||||||
|
.config
|
||||||
|
.node
|
||||||
|
.name}.net.lan"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
'')
|
||||||
|
+ ''
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
|
@ -40,6 +40,8 @@
|
||||||
./telegraf.nix
|
./telegraf.nix
|
||||||
./wireguard-proxy.nix
|
./wireguard-proxy.nix
|
||||||
./wireguard.nix
|
./wireguard.nix
|
||||||
|
|
||||||
|
./d2diag.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
nixpkgs.overlays = [
|
nixpkgs.overlays = [
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue