2023-12-12 13:12:15 +00:00
# pkgs.checkpointBuildTools {#sec-checkpoint-build}
2022-06-27 12:03:10 +00:00
2023-12-13 10:15:29 +00:00
`pkgs.checkpointBuildTools` provides a way to build derivations incrementally. It consists of two functions to make checkpoint builds using Nix possible.
2022-06-27 12:03:10 +00:00
2024-01-07 10:57:04 +00:00
For hermeticity, Nix derivations do not allow any state to be carried over between builds, making a transparent incremental build within a derivation impossible.
2022-06-27 12:03:10 +00:00
However, we can tell Nix explicitly what the previous build state was, by representing that previous state as a derivation output. This allows the passed build state to be used for an incremental build.
2023-12-12 12:19:21 +00:00
To change a normal derivation to a checkpoint based build, these steps must be taken:
2024-01-07 10:57:04 +00:00
- apply `prepareCheckpointBuild` on the desired derivation, e.g.
2023-12-12 13:12:15 +00:00
```nix
2024-03-27 18:10:27 +00:00
{
checkpointArtifacts = (pkgs.checkpointBuildTools.prepareCheckpointBuild pkgs.virtualbox);
}
2023-12-12 13:12:15 +00:00
```
2024-01-07 10:57:04 +00:00
- change something you want in the sources of the package, e.g. use a source override:
2023-12-12 13:12:15 +00:00
```nix
2024-03-27 18:10:27 +00:00
{
changedVBox = pkgs.virtualbox.overrideAttrs (old: {
src = path/to/vbox/sources;
});
}
2023-12-12 13:12:15 +00:00
```
2024-01-07 10:57:04 +00:00
- use `mkCheckpointBuild changedVBox checkpointArtifacts`
2023-12-12 13:12:15 +00:00
- enjoy shorter build times
2022-06-27 12:03:10 +00:00
2023-12-12 13:12:15 +00:00
## Example {#sec-checkpoint-build-example}
```nix
2024-01-07 10:57:04 +00:00
{ pkgs ? import < nixpkgs > {} }:
2023-12-12 13:12:15 +00:00
let
2024-01-07 10:57:04 +00:00
inherit (pkgs.checkpointBuildTools)
prepareCheckpointBuild
mkCheckpointBuild
;
helloCheckpoint = prepareCheckpointBuild pkgs.hello;
2023-12-12 13:12:15 +00:00
changedHello = pkgs.hello.overrideAttrs (_: {
doCheck = false;
patchPhase = ''
sed -i 's/Hello, world!/Hello, Nix!/g' src/hello.c
'';
});
2024-01-07 10:57:04 +00:00
in mkCheckpointBuild changedHello helloCheckpoint
2023-12-12 13:12:15 +00:00
```