Getting started
gen is not a framework you install. It’s 22 small libraries, and the fastest way in is to take exactly one of them. No hub, no nixpkgs, no NixOS module — a flake, ten lines of data, and a question answered.
-
Add one library
Section titled “Add one library”Every gen library is a flake that exports one
.lib. Takegen-graph— pure graph queries, nothing else pulled in:flake.nix {inputs.gen-graph.url = "github:sini/gen-graph";outputs = { gen-graph, ... }:letgraph = gen-graph.lib;myData = {web = { deps = [ "api" ]; };api = { deps = [ "cache" "database" ]; };cache = { deps = [ "database" ]; };database = { deps = [ ]; };};g = {edges = id: myData.${id}.deps or [ ];parent = id: myData.${id}.parent or null;nodes = builtins.attrNames myData;nodeData = id: myData.${id};};in{reachableFromWeb = graph.reachableFrom g "web";roots = graph.roots g;};}myDatais your own data — nothing here is gen vocabulary yet.gis the one thing gen-graph asks for: four accessor functions over it. Nothing is copied or re-shaped;edgesandnodeDatajust readmyDatadirectly. -
Ask it a question
Section titled “Ask it a question”Terminal window nix eval --json .#reachableFromWeb# ["api","cache","database"]nix eval --json .#roots# ["web"]That’s a resolved graph:
webdepends (transitively) on everything gen-graph just listed, andwebis the only node nothing else points at.
What just happened
Section titled “What just happened”myData held the nodes. The deps field held the relation between them — an edge. g
told gen-graph how to read both off data you already owned. reachableFrom and roots
are queries over that relation; gen-graph never stored a graph of its own, it answered
questions about yours.
That’s the whole model the rest of the ecosystem builds on: nodes are data, relations are edges, and you get answers by asking rather than by assembling them by hand.
Where to go next
Section titled “Where to go next”Palettes adapted from Catppuccin (Macchiato) (MIT), Tokyo Night (Apache-2.0), gruvbox (MIT), Catppuccin (Latte) (MIT), Rosé Pine (Dawn) (MIT).