Skip to content

Instantly share code, notes, and snippets.

@FRidh
Last active August 5, 2022 16:49
Show Gist options
  • Save FRidh/be0065018726af6651fe5f435d9569b6 to your computer and use it in GitHub Desktop.
Save FRidh/be0065018726af6651fe5f435d9569b6 to your computer and use it in GitHub Desktop.

Nixpkgs: issues with stdenv.mkDerivation

This document describes some of the issues that exist with stdenv.mkDerivation and that could or should be considered when redesigning it.

Phase ordering

stdenv.mkDerivation comes with several fixed phases. It is possible to override these phases or add other phases. It is however difficult to make phases depend on one another as that requires describing their relative order and that is unfortunately not possible.

As an example, there are multiple Python-related hooks that add to postFixupHooks. Certain hooks depend on other hooks, yet all get added to postFixupHooks, and it is not known in which order they get executed.

Possible solution

A possible solution is to topologically sort the phases and have phases define before and after phases.

Lack of structured logging

There is no support for logging. Currently anything can write to stdout or stderr. There are no abstractions for providing structured output. For example, it would be useful a certain message would be printed if a phase started and finished.

Default phases use make

The default phases expect make. While a lot of core software uses make, this is irrelevant for most non-C/C++ software.

Possible solution

Support for make should be a setup hook providing phases as is done also for other build systems.

Phase attributes

Many hooks providing custom phases listen to specific environment variables that were defined for the hook in question. There is no structure for specifying these variables.

Possible solution

Use structured attributes and let each hook/phase have an attribute set in the e.g. a phases set. Each hook could provide a schema, e.g. using jsonschema or using the NixOS module system.

Hook and phase discoverability

It is difficult to determine what is causing something to run during a build. It is difficult to find out which variables affect the build.

Possible solution

Structured logging that shows the decisions that were made and which variables were used for this.

meta emphasis on Nixpkgs

The meta attribute set provides useful metadata about packages. Having this possibility to store metadata is useful for packages inside Nixpkgs but also outside.

Derivation scope is building, installing and testing

Generally speaking the build, installation and testing of a package is done in one derivation. This is not always desirable since e.g. testing may require additional dependencies increasing the total work that needs to be done when rebuilds are needed.

An example here are Python packages, specifically those containing extension modules (compiled code). Tests are typically enabled and can take a long time. If a test fails, the whole builds fail, requiring not just rerunning the test-suite but also the entire build. Furthermore, there are typically a lot of test-time dependencies that are now added to the build-time closure.

Possible solution

Offer first-class support for installation and/or testing in separate derivations. This can flatten the dependency tree and reduce the amount of work that needs to be done. This becomes especially interesting in connection with content-addressed derivations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment