Getting Started
gen is a set of small Nix libraries, and you can use any one of them on its own. This guide
takes gen-graph, gives it four nodes, and asks two questions about them. You need a flake
and ten lines of data. No nixpkgs input is required.
-
Add one library
Section titled “Add one library”Every gen library is a flake that exports a
.lib.gen-graphanswers graph queries:flake.nix {inputs.gen-graph.url = "github:sini/gen-graph";outputs = { gen-graph, ... }:letgraph = gen-graph.lib;myData = { # (1)web = { deps = [ "api" ]; };api = { deps = [ "cache" "database" ]; };cache = { deps = [ "database" ]; };database = { deps = [ ]; };};g = { # (2)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"; # (3)roots = graph.roots g;};}myDatais your own data. None of its field names mean anything to gen.gis an accessor record: four functions that tell gen-graph how to read your data.edgesreturns the nodes a node points to,parentreturns its container,nodeslists every node andnodeDatareturns a node’s attributes.- Each output is a query over
g.
-
Ask it a question
Section titled “Ask it a question”Terminal window nix eval --json .#reachableFromWeb# ["api","cache","database"]nix eval --json .#roots# ["web"]webdepends on the three listed nodes, directly or through other nodes.webis the only node that no other node points to.
What just happened
Section titled “What just happened”myData held the nodes, and its deps fields held the edges between them. g told
gen-graph how to read both from data you already had. reachableFrom and roots are
queries over that relation. gen-graph keeps no copy of the graph.
The rest of gen builds on the same model. Hosts, users and features are nodes, the relations between them are edges, and you get results by querying the graph.
Every gen library runs its test suite on every push under three evaluators: upstream Nix, Determinate Nix and Lix, each pinned to its latest release. See Trust.
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).