Debugging closure sizes graphically
Jade Lovelace <jadel@mercury.com>
NixCon 2022
October 20, 2022
https://jade.fyi
# who am I? * Computer Engineering student at UBC in Vancouver, BC, Canada * Presently interning in backend dev for Mercury, a company offering banking
1
designed for the unique needs of startups * Haskell + TypeScript + Nix stack * Working on internal tools for risk management
Mercury is a financial technology company, not a bank. Banking services provided by Choice Financial Group and Evolve Bank & Trust, Members FDIC.
# what's closure size? * Size of some derivation and everything it depends on * Accidental dependencies are the major contributor * Other systems don't have this problem: forgetting about runtime dependencies may silently fail (or work if you have them installed!) at runtime * "Closure" → like a function referencing values outside it
# how do I create a dependency? * Only what goes in may go out: inputs may become runtime dependencies if they appear in the output * Follows from Nix's hermetic design: outputs are a strict subset of inputs * It's easy to cause accidental dependencies
# ok, but what does "appear" mean? ``` grep -r '[0-9abcdfghijklmnpqrsvwxyz]{32}' $out ``` Seriously. Nix looks for 32 character strings forming the hash part of any of the store paths of the closure of the inputs to the derivation See Figure 5.12 in the Nix thesis
# digression: "what went in?" Nix strings are magic: they keep track of the derivations that they've referenced as "string context", and propagate that information into any derivations they land in.
# what does my stuff depend on?
# that's a graph though Yeah. I can't tell what the relationship is between these. No tree or graph mode for nix path-info unlike nix-store --query (the latter is not stellar anyway)
# what if..? haha, jk, unless? There is a JSON output mode, what if we just used that? and then did some stuff to it Some purely functional programming in jq later: `nix-closure-graph nixpkgs#python3 > python3Closure.svg`
# cool
# what about a nixos image whoops
# well that didn't work I built this graph viewer prototype at work, I wonder if I could stick a NixOS closure into it FIXME!!!
# other projects from me https://docs.jade.fyi - Single page HTML docs for GNU, postgres, and zsh https://github.com/LF-/nix-doc - Interactive function documentation for Nix https://github.com/LF-/nix-otel - Trace Nix builds with OpenTelemetry
# Mercury is hiring! Front-end, back-end, management, design, data https://mercury.com/jobs