Cleaning Up Core

I came up with a format and got bootTools working, which is one of the fundamental derivations.

I’m trying out a format like this:

  • nodes/
    • 0_lib/
      • (submodule to lib)
      • default.nix
      • static/
        • setup.json # stuff like maintainers, licenses, and a list of OS triples. Things other tools might want to parse/use
        • meta.json # empty obj
    • 1_func_macBootTools
      • default.nix
      • static/
        • setup.json # has fetch URLs and sha hashes, making them easy to auto-update without generating nix code
        • meta.json # says what script command generates the setup.json
    • 2_drv_bootTools_darwin-aarch-64
      • default.nix
      • static/
        • setup.json # drv name
        • meta.json

The idea being each node is a func (nix helper), lib (nix helper but not a function) or a drv.

Importantly, to be performant and ensure there are no looping dependencies, the default.nix for drv is not typical. Its not a function that takes lib and pkgs, its not a func at all. Instead its just an expression that directly imports all dependencies at the top. For example:

let # for static dependency analysis this "let" intentionally only contains direct imports
  lib = import ../0_lib;
  macBootTools = import ../1_func_macBootTools;
in
  # real code starts here
  let
    static = lib.loadStatic ./.;
  in
    derivation {
        name = static.setup.name;
        # ...
    }

Right now, using nix-visulize and nixpkgs we have to build all the derivations before we can visualize the dependency tree. And the tree is system/OS specific. But this^ new format would allow us to statically analyze the dependency tree, including dependence on nix-code not just dependence on derivations. We can even generate a dependencies.json for each node to make it really easy for other tools to parse.

The format might run into problems later, but its what I’m trying for now.

5 Likes