Boot a Custom Image¶
One exec app on its own NixOS guest system, in place of the worker image. Kernel modules, drivers and system services of the job go into the custom image.
Requirements:
- An exec app, see Declare an Exec App
- An exec worker allowing custom images, see Set Up an Exec Worker
1. Allow Custom Images¶
Jobs with image wait for a worker with exec.allow.customImages. That setting defaults to false.
2. Define the Image¶
# flake.nix
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.gradient.url = "github:wavelens/gradient";
outputs = { self, nixpkgs, gradient }: let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
in {
nixosConfigurations.trainer = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
gradient.nixosModules.guest # (1)!
({ config, ... }: {
gradient.guest.enable = true;
nixpkgs.config.allowUnfree = true;
hardware.graphics.enable = true;
hardware.nvidia.open = true;
services.xserver.videoDrivers = [ "nvidia" ];
system.stateVersion = "26.05";
})
];
};
apps.x86_64-linux.train = {
type = "app";
program = "${pkgs.writeShellScript "train" "nvidia-smi && python train.py"}";
passthru.gradient = {
image = self.nixosConfigurations.trainer;
devices = [ "gpu:h100:8" ];
};
};
};
}
- Guest agents and the guest store image come from the
gradient.guestmodule. Images without that module fail evaluation withimage has no config.system.build.gradientGuest, import the gradient.guest module.
3. Keep the Image in Step¶
- Workers build the image the same way they build the program.
- Jobs with an image run on a fresh guest, booted cold from the image.
- Warm guests stay untouched.
- Guests see the store paths of the image and the program closure only. Paths of the worker store remain out of reach.
cpusandmemoryMbcome from the worker image. The custom image settings don't count.- Guest agents in the image come from the
gradientinput. Keep that input at the server version. - Agents from older releases start the program in
/work. Those agents can refuse shells.
Verify Deployment¶
- Jobs reach
runningon a worker withexec.allow.customImages. - Custom image boot failures fail the attempt and consume a retry.
Next Steps¶
- Set Up an Exec Worker: the worker image and
exec.allow - Declare an Exec App: every
passthru.gradientfield - Configuration:
exec.allow.customImages