|
1 | 1 | # Using the kernel builder with Nix |
2 | 2 |
|
3 | 3 | The kernel builder uses Nix for building kernels. You can build or |
4 | | -run the kernels directly if you have [Nix installed](https://nixos.org/download/) |
5 | | -on your system. On systems without Nix you can use the [Docker](./docker.md) |
6 | | -image, which is a wrapper around Nix. |
| 4 | +run the kernels directly if you have Nix installed on your system. |
| 5 | +We recommend installing Nix in the following way: |
| 6 | + |
| 7 | +- Linux: use the [official Nix installer](https://nixos.org/download/). |
| 8 | +- macOS: use the [Determinate Nix installer](https://docs.determinate.systems/determinate-nix/). |
7 | 9 |
|
8 | 10 | ## Getting started |
9 | 11 |
|
@@ -35,9 +37,6 @@ cd examples/activation |
35 | 37 | nix build . -L |
36 | 38 | ``` |
37 | 39 |
|
38 | | -You can put this `flake.nix` in your own kernel's root directory to |
39 | | -get add Nix support to your kernel. |
40 | | - |
41 | 40 | ## Shell for local development |
42 | 41 |
|
43 | 42 | `kernel-builder` provides shells for developing kernels. In such a shell, |
@@ -82,6 +81,39 @@ nix develop -L .#test |
82 | 81 | python -m pytest tests |
83 | 82 | ``` |
84 | 83 |
|
| 84 | +## Adding test dependencies to development shells |
| 85 | + |
| 86 | +You can add test dependencies to a development or testing shell. Adapt |
| 87 | +the kernel's `flake.nix` to use the `pythonCheckInputs` option: |
| 88 | + |
| 89 | +```nix |
| 90 | +{ |
| 91 | + description = "Flake for my kernel"; |
| 92 | +
|
| 93 | + inputs = { |
| 94 | + kernel-builder.url = "github:huggingface/kernel-builder"; |
| 95 | + }; |
| 96 | +
|
| 97 | + outputs = |
| 98 | + { |
| 99 | + self, |
| 100 | + kernel-builder, |
| 101 | + }: |
| 102 | + kernel-builder.lib.genFlakeOutputs { |
| 103 | + path = ./.; |
| 104 | + rev = self.shortRev or self.dirtyShortRev or self.lastModifiedDate; |
| 105 | +
|
| 106 | + # The einops and numpy test dependencies are added here: |
| 107 | + pythonCheckInputs = pkgs: with pkgs; [ einops numpy ]; |
| 108 | + }; |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +The available packages can be found on [search.nixos.org](https://search.nixos.org/packages?channel=25.05&query=python312Packages). |
| 113 | + |
| 114 | +Keep in mind that these additional dependencies will only be available to |
| 115 | +the Nix shells, not the final kernel uploaded to the Hub. |
| 116 | + |
85 | 117 | ## Building a kernel without `flake.nix` |
86 | 118 |
|
87 | 119 | If a kernels source directory does not have a `flake.nix` file, you can build the |
|
0 commit comments