Skip to content

Latest commit

 

History

History

fractals

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Fractals

Fractals are third party Fractalide libraries.

What?

Fractals are importable 3rd party sets of nodes, subgraphs and edges, this folder hierarchy is the single source of truth regarding where to find each community fractal.

Why?

Fractals allow the community to develop their own projects in their own git repository, and once ready, may plug into dev/fractalide/fractals folder hierarchy which represents the spine of Fractalide. Once inserted your fractal is available for use by everyone.

Who?

Anyone making high quality, documented nodes, subgraphs and edges may plug into this folder hierarchy. We use the C4 so your fractals will be merged in quickly.

Where?

Each fractal needs to have its own hierarchical folder. For example, HTTP would be placed in the fractalide/fractals/net/http folder.

How?

Say you wish to create a http project, these are the exact steps involved:

  • Ensure you use this directory structure convention:

dev
├── fractalide
│   └── fractals
│       └── net
│           └── http
│               └── default.nix
└── fractals
    ├── fractal_net_http
    └── ... more community fractals cloned
$ cd <your/development/directory>
$ git clone \https://gitlab.com/fractalide/fractalide.git
$ NIX_PATH="nixpkgs=https://github.com/NixOS/nixpkgs/archive/125ffff089b6bd360c82cf986d8cc9b17fc2e8ac.tar.gz:fractalide=/path/to/dev/fractalide" && export NIX_PATH` (1)
$ mkdir dev/fractals && cd dev/fractals
$ git clone git://github.com/fractalide/fractal_workbench.git fractal_net_http (2)
$ git remote set-url origin git://new.url.you.control.here
$ mkdir -p dev/fractalide/fractals/net/http/ (3)
  1. Take note when setting the NIX_PATH environment variable, it must include the path to your newly cloned fractalide repo i.e.: NIX_PATH=…​:fractalide=/path/to/dev/fractalide.
    Should you start a new shell, type <ctrl>-r then type 125ff this will search your command history for the above command, or just persist the command in your ~/.bashrc file.

  2. The fractal_workbench repo provides a minimum correct structure for your fractal. Keep the repo naming convention fractal_* for your repo as it’ll be easy for the community to see this is a fractalide related project.

  3. Create your needed directory hierarchy dev/fractalide/fractals/net/http/default.nix.

Insert the below code into a file called default.nix which sits in the above folder.

dev/fractalide/fractals/net/http/default.nix
{ pkgs
, support
, edges
, nodes
, fetchFromGitHub
, ...}:
let
  fractal = fetchFromGitHub {
    owner = "fractalide";
    repo = "fractal_net_http";
    rev = "66ad3bf74b04627edc71227b3e5b944561854367";
    sha256 = "1vs1d3d9lbxnyilx8g45pb01z5cl2z3gy4035h24p28p9v94jx1b";
  };
  /*fractal = ../../../../fractals/fractal_net_http;*/
in
  import fractal {inherit pkgs support edges nodes; fractalide = null;}
Note
  • The pkgs, support, nodes, edges and fetchFromGitHub are arguments passed into this closure.

  • The let expression contains a fetchFromGitHub expression describing the location of the fractal.

    • owner of the git repository i.e.: github.com/fractalide

    • repo is the git repository in question i.e.: github.com/fractalide/fractal_net_http

    • rev indicates the git revision you want to import i.e.: https://github.com/fractalide/fractal_net_http/commit/66ad3bf74b04627edc71227b3e5b944561854367

    • sha256 is a neat nix mechanism to assist in deterministic builds. To obtain the correct sha256 try build your project with an incorrect sha256 (change the first alpha-numeric character in 1vs1d3d9lbxnyilx8g45pb01z5cl2z3gy4035h24p28p9v94jx1b to a 2). Nix will download the repository and check that the actual sha256 matches against what you incorrectly inserted. Nix will tell you what the correct sha256 is. Copy it and insert the correct sha256, replacing 2vs1d3d9lbxnyilx8g45pb01z5cl2z3gy4035h24p28p9v94jx1b.

  • Please notice the line: /*fractal = ../../../../fractals/fractal_net_http;*/ This line allows you to tell nix not to refer to the remote repo but your local clone of fractal_net_http. Comment out the fetchFromGitHub expression and uncomment the above local repo clone path. When you publish your fractal upstream, ensure this line is commented out! Please use a relative path compatible with the above directory structure convention as it will work for everyone and we don’t have to hunt for the correct folder. Just un/comment and go!

  • The line: import fractal {inherit pkgs support edges nodes; fractalide = null;} is where we import your closures into `fractalide’s set of closures. Thus making your nodes available to everyone.

The last step is to expose the exact nodes / edges to dev/fractalide/nodes/default.nix and dev/fractalide/edges/default.nix.
This is done in this manner:

  • Open dev/fractalide/nodes/default.nix and seek out the net_http_nodes attribute. This is what it looks like: net_http_nodes = fractals.net_http.nodes; In this case there is no specific top level node you’d wish to expose so the convention _nodes is used to indicate this. Whereas if you have a specific node you’d wish to expose then you’d name it as such: net_http = fractals.net_http.nodes.http. Why the .http? well that’s what the node is named in the namespace here. Please notice the lack of the *_nodes when exporting a single node.

  • Regarding importing edges, typically you don’t need to import edges, but there are times when you need a special edge which must operate on the public side of the fractal and thus usable across a number of fractals, say the net_http_edges.request You’d use a similar mechanism as above when exposing your edges.

Incremental Builds

Incremental Builds speed up the development process, so that one doesn’t have to compile the entire crate from scratch each time you make a change to the source code.

Fractalide expands the nix-build system for incremental builds. The Incremental Builds only work when debug is enabled. They also need the path to a cache folder. The cache folder can be created from an old result by the buildCache.sh script. Per default the cache folder is saved in the /tmp folder of your system. Incremental Builds permit you to compile a crate without having to recompile the crate dependency tree.

Here is an example how you can build with the Incremental Build System:

$ cd dev/fractalide
$ nix-build --argstr debug true --argstr cache $(./support/buildCache.sh) --argstr subgraph workbench

If you’re using NixOS, please ensure you have not set nix.useSandbox = true;, otherwise Incremental Compilation will fail.

There is a service.nix file! What is it?

Two ways to execute your fractal

Executing from within Fractalide

$ cd dev/fractalide
$ nix-build --argstr rs workbench
$ ./result
  • advantages

    • Incremental recompilation needed for development

  • disadvantages

    • wetware needed to plug into dev/fractalide/fractals to get incremental recompilation

    • long build command

Executing from with the Fractal

$ cd /dev/fractals/fractal_workbench
$ nix-build
$ ./result
  • advantages

    • faster to test by just issuing the nix-build command

    • convenient for CI & CD of you specific subgraph

    • don’t have to plug it into dev/fractalide/fractals

  • disadvantages

    • no incremental recompilation