New POC Proposal
Cartenix: a Proof of concept allowing you to run Nix inside the Cartesi virtual machine leveraging its determinism to accomplish complete reproducibility.
Core Concept and purpose statement
Nix is a set of software that takes a unique approach to package management and system configuration.
Nix allows you to build packages in sandboxes making you declare all the dependencies (both sources and other packages built with Nix). This ensures a high degree of reproducibility and hermeticity (i.e. if a package works on one machine, it will also work on another). It also allows having different versions of the same package with different dependencies installed on the same machine, effectively solving the ādependencies hellā problem.
Thus we can say that Nix provides an infrastructure to reproducibly build software.
Unfortunately, since everything should be built from scratch otherwise, it has to rely on big centralized caches (substituters/binary caches in the Nix terminology) to speed up things. These caches are continuously populated by a set of trusted builders.
Cartesi would remove this need for trust in centralized builders.
We developed an early POC at ETHGlobal Lisbon winning the āCartesi Best Useā award. The project is already listed in the ETHGlobal showcase.
Technical clarification about the early POC: during the Hackathon, we successfully executed Nix primitive operations able to produce outputs in the Nix store but not building derivations (though we were close).
The goal is therefore to expand the concepts and experience gathered so far to move forward with the development of a POC that actually succeeds in enabling a generic reproducible build system in a deterministic environment, generalizing its architecture without resorting to time-imposed shortcuts.
How will you use Cartesi, specifically?
In our proof-of-concept project, Cartenix, we will be using Cartesi specifically to enable reproducible builds using Nix. By leveraging the Cartesi virtual machine, we aim to remove the need for trust in centralized builders, which is a limitation of the traditional Nix build process.
Hereās an overview of how we will use Cartesi in our POC:
- Architecture Overview: We will utilize the Cartesi VM and integrate it with the Nix package system. The Cartesi VM provides a deterministic and secure environment for executing the Nix builds.
- Nix Package System Integration: We will create a Docker image containing a RISC-V Nix installation and a set of already-built dependencies, this container will run in the Cartesi VM environment. Weāll try to shrink this set of dependencies until it contains only sources (that cannot be downloaded from inside the Cartesi VM)
- Reproducible Builds: By running the Nix builds inside the Cartesi VM, which is deterministic, weāll achieve complete reproducibility.
- Eliminating Trust in Caches: With Cartesi, we will remove the reliance on centralized caches (substituters/binary caches) in the Nix packages system. This enhances security and eliminates potential vulnerabilities associated with trusting external caches.
By combining Cartesi and Nix, we address one of the big problems of any distributed build infrastructure leveraging on the trustlessness of the blockchain.
For a more detailed understanding of our approach and the technical aspects of the project, you can refer to the āCore Concept and Purpose Statementā and āTechnical Detailsā sections.
Technical details
Rudiments: Nix, as well as a build infrastructure, is also a purely functional and lazy DSL that lets you easily define derivations. Nix derivations are the ābuild recipesā that, given to the Nix daemon, are built to their outputs (e.g. usually packages but in general they are just directories containing files). During the code evaluation, Nix implicitly creates the dependencies graph and the build plan.
Derivations outputs are hashed using some attributes among which are the name, the architecture, and the hashes of their dependencies. When traversing the dependencies graph of a derivation output you can find some special fixed output derivations (FOD) which are simply derivations that need internet access, then cannot be built inside a sandbox. To ensure reproducibility Nix demands to declare the content hash of the output of these FODs.
Itās important to notice this duality in the hashing: normal derivations (that are built inside sandboxes) are input addressed while fixed output derivations (that are fetched) are content addressed (actually there is an experimental feature behind a flag that enables content addressing for all the derivations).
More information about the Nix model is available in the creatorās Ph.D. thesis
As the Cartesi VM does not have internet access, all the (transitive) dependencies (which usually are simply sources) must be provided within the VM. This means that, when we create the Docker image, we have to know in advance all the fixed output derivations that will be needed by the build. For this reason, weāll create a different Docker image for every derivation that is going to be built. However, this image creation process will be automatized.
Here is a high-level overview of the technical steps involved in the POC development proposal:
- Generalize the build and installation process of Nix for the RISC-V architecture to make it more adaptable
- Ensure that Nix is properly installed in a Docker image based on
cartesi/python:3.10-slim-jammy
(e.g. avoid hard coded paths) - Update the Dockerfile to get programmatically all the fixed output derivations in the build closure of the target derivation output
- Move away from the early POCās reliance on the simple primitive
builtins.toFile
that we adopted to build a dependency-free package. - Update the nix.py or generalize the quick start example to enhance the interaction and allow retrieving useful information about the build process (e.g. outputās content hash)
The final goal is, given a Nix derivation, provide a programmatic way to create a docker image able to build that derivation inside the Cartesi VM.
Value Proposition
This project is a valuable addition to the Cartesi developer ecosystem and core technology, as it tackles the challenges of reproducible builds using the Nix package system within the Cartesi VM. The successful execution of this POC offers several compelling reasons for the community and other developers to take an interest:
-
Enhancing Reproducibility: Cartenix leverages the deterministic nature of the Cartesi VM and seamlessly integrates it with the Nix package system, enabling deterministic and fully reproducible builds.
-
Eliminating Trust in Centralized Caches: The POC aims to remove the reliance on centralized caches (substituters) in the Nix package system, enhancing security and reducing vulnerabilities associated with external caches.
-
Fostering Collaboration and Innovation: The successful execution of Cartenix paves the way for collaboration between the Cartesi and Nix communities. It encourages the exploration of novel ideas and solutions that leverage the strengths of both technologies, fostering innovation and knowledge sharing among developers.
Subsequent Vision and Extensibility
To extend the functionality of the POC, the following immediate next steps and features that could be implemented are:
-
CLI Integration: Introducing a command-line interface (CLI) via sunodo, a command runner for Cartesi, would enhance the user experience and allow developers to interact with Nix and Cartesi more efficiently.
-
Shared Computation: Enabling shared computation among multiple Cartesi VM instances would enhance resource utilization by reusing already built trusted artifacts. Developers could leverage distributed computing capabilities to accelerate the build process, reduce latency, and improve overall efficiency.
-
IPFS/Shared Cache for Dependencies: Integrating IPFS or a shared cache mechanism for storing and retrieving dependencies would optimize the build process. This would reduce the reliance on individual developers to provide all the necessary dependencies, improving efficiency and enabling easier collaboration among developers working on similar projects.
-
Nix for Docker Images: Using Nix to build Docker images for the Cartesi VM would further enhance the reproducibility and portability.
-
Recursive Cartenix: Build above mentioned Docker images using Cartenix itself
Risks and Contingency Plans
This project may face some potential challenges. Here are some examples and proposed contingency plans:
-
Technical Limitations: The POCās success relies on the effective integration of the Nix Package system with the Cartesi VM. If technical limitations or compatibility issues arise during the implementation, it may hinder the progress of the project. Those limitations could also be related to resource availability, such as RAM and CPU within the Cartesi VM.
-
Dependencies and Complex Applications: As the project aims to generalize the build process and handle complex software dependencies, there may be challenges in managing and integrating a wide range of dependencies (e.g. Nixpkgs support for RISC-V is suboptimal).
To mitigate those risks, the development team will actively engage with the Cartesi community and seek support from the Cartesi team to address any technical challenges that arise.
Success criteria & Deliverables
The success criteria for the Cartenix POC can be defined as follows:
-
Generalized Build and Installation Process: The POC will be considered successful if the build and installation process of Nix for the riscv64 architecture is generalized and made adaptable.
-
Dependency Source Provisioning: Success will be achieved if the POC effectively adapts the step of providing dependency sources. This should ensure that all the fixed output derivations and necessary dependencies are accurately fetched and included within the Cartesi VM during the image build.
-
Generalized Software and Dependencies: The success criteria involve successfully generalizing the software to be built and its dependencies. The POC should demonstrate the ability to build a non-trivial application with complex dependencies.
Deliverables
- The entire codebase under a permissive Apache-2.0 open source license
- A readme file that provides an overview of the project and that provide a comprehensive documentation
- Sample Builds: demonstrations of successfully built software using the generalized process
Estimated Duration and Funds Requested
Duration: 4 weeks
Funds request for the POC: 5000 USD
About Your Development Team
The development team for the Cartenix project consists of two:
- Role: DevOps Engineer and Nix developer at MLabs
- Role: CTO at Beatdata, Agile & Blockchain enthusiast
CC. @aciceri
ERC-20 Payee address
0xAF0DE9616735ED16E25F0C08829d5E37068dd375