Build a Repository Without flake.nix¶
Nix repositories that have default.nix or shell.nix build on Gradient without a hand-written flake.nix. Lookups such as <nixpkgs> come from the project's Nix channels. Evaluations fix the channel version.
Requirements:
- A project with a task, see First Project.
- Workers with the same Gradient version as the server. Older workers do not take evaluations of a project with Nix channels turned on.
1. Turn On Nix Channels¶
The saved channels remain when the setting is off. Repositories without flake.nix fail evaluation again. The trigger for Nix channels can no longer fire.
2. Add Channels¶
A name and a URL make up each channel. The name is the reference name in Nix. The target of the nixpkgs channel is <nixpkgs> and every path under it, such as <nixpkgs/lib>.
Open Settings -> Nix channels -> Add channel. Enter the name nixpkgs and the URL https://channels.nixos.org/nixos-unstable.
- Name: Letters, digits,
_,-. The first character is a letter or_. The nameselfstays reserved for the flake itself. - URL: http or https without credentials. URLs with a tarball extension (
.tar.xz,.tar.gz,.tar.bz2,.tar.zst,.tgz,.zip) remain unchanged. Other URLs get/nixexprs.tar.xzappended. - Private Hosts: Hosts on a private network need an entry in
outbound.allowedNonPublicNetworkTargets. See Configuration. - Credentials: Gradient does not support channels that need a login.
3. Point the Task at legacyPackages¶
Some commits have no flake.nix. Generated flake.nix and flake.lock files take their place. Project channels turn into locked tarball inputs. Task wildcards then select outputs from the generated flake.
| File | Flake output | Wildcard |
|---|---|---|
default.nix |
legacyPackages.<system> |
legacyPackages.x86_64-linux.* |
shell.nix |
devShells.<system>.default |
devShells.x86_64-linux.default |
- Files that evaluate to a function get an empty attribute set
{ }as argument, likenix-build. Functions with required arguments can fail with a Nix error. - Single derivations turn into
default. Lists turn into attribute sets whose names are the positions0,1, ... - All outputs exist in
x86_64-linux,aarch64-linux,x86_64-darwin,aarch64-darwin. Outputs read their system frombuiltins.currentSystem. <name>with no project channels can fail with the usual error from a Nix lookup.- Evaluation is pure and restricted. Three things don't work, namely
builtins.fetchTarballwithout a hash,builtins.currentTimeand environment variables.
The wildcard field of Connect repository shows the legacyPackages hint for projects with Nix channels.
4. Follow Channel Updates¶
A trigger for a Nix channel can start an evaluation of an unchanged commit on a newer tarball from the project channel. Builds of unchanged packages come from the cache. See Nix Channel for the rules.
Pick the trigger type Nix channel on the task's Triggers page. Connect repository offers the same trigger as a checkbox.
Add a trigger for a Nix channel to an existing task.
Pins¶
- Evaluations record the exact tarball for every channel, with the locked URL, NAR hash and last modified time.
- Retries of an evaluation reuse that pin. New evaluations re-resolve every channel.
- Channel servers such as channels.nixos.org respond with redirects and immutable link headers. Locks use that immutable URL in place of the moving channel URL.
Limits¶
- Exec jobs check out the real commit without generated files. A job can't use
nix run .#appin these repositories. - Pull requests that update
flake.lockneed a realflake.nixin the repository. gradient evalandgradient build --runneedflake.nix.gradient buildandgradient downloadin a directory withoutflake.nixturn bare attribute names intolegacyPackages.<system>.<name>.- Overrides of a flake input by channel name replace that channel for that task. Builds that use
gradient build --override-input nixpkgs github:NixOS/nixpkgsuse that flake reference instead of the channel.
Verify Deployment¶
Evaluation pages show a banner Evaluated through a generated flake.nix. The banner rows list each channel with the lookup name, locked URL, NAR hash and date. Wildcards with no match fail the evaluation and add a hint to legacyPackages.<system>.