Publish and Read Nix Channels¶
A channel task can publish the latest commit of a branch as a Nix channel. A channel can only move forward after every build succeeded. Hosts follow it with nix-channel --add. Flakes lock it as a tarball input. Binaries come from the Gradient cache.
Requirements:
- A project with a cache and a worker, see First Project.
- A repository with a
default.nixor aflake.nix. Repositories withoutflake.nixalso need Nix channels on the project.
1. Create a Channel Task¶
Channel tasks evaluate and build like other tasks. They publish too. The channel branch is the only branch where the channel can track the commit.
Open Connect repository in a project with Nix channels on. Select Build and publish channel as Kind and enter Channel branch. Existing tasks change kind in Settings -> General.
The channel URL is https://gradient.example.com/channel/acme/stable.
2. Subscribe with nix-channel¶
Add the channel URL with a name of choice and fetch the newest tarball. Lookup paths like <stable> then resolve to the channel.
nix-channel --add https://gradient.example.com/channel/acme/stable stable
nix-channel --update stable
3. Use as Flake Input¶
Tarball inputs lock to the immutable URL of the current update. Use nix flake update stable to move the lock to the latest update. Set flake = false for repositories without flake.nix.
# flake.nix
{
inputs.stable = {
url = "https://gradient.example.com/channel/acme/stable/nixexprs.tar.xz";
flake = false;
};
}
4. Private Projects¶
Public projects don't need a login. Private projects need authentication with HTTP Basic. Any text works for the username. Set the password to an API key with access to the project. Login tokens (JWT) work as password too. Nix tools read credentials from a netrc file.
Channel Updates¶
Channels advance to the evaluation if all of these conditions are true.
- The evaluation ran on the channel branch, for the task's repository, outside a pull request.
- The evaluation evaluated the task's own wildcard. A manual run of one attribute does not count.
- Every build succeeded and the evaluation completed. Tasks with Only Evaluate have no builds and advance on a completed evaluation.
- The commit is the head of the newest evaluation of the branch and the channel is not on it yet.
A retry of the head evaluation can advance the channel. A retry or manual run with an explicit older commit cannot advance the channel. Channels never move backwards.
| Path | Response |
|---|---|
/channel/<project>/<task> |
JSON with the current commit and update |
/channel/<project>/<task>/nixexprs.tar.xz |
302 to the tarball of the current update, with a Link: <...>; rel="immutable" header |
/channel/<project>/<task>/git-revision |
Commit hash as plain text |
/channel/<project>/<task>/updates/<update>/nixexprs.tar.xz |
Tarball of one update. 410 once retention removed it |
- Tarballs contain one directory
<task>-<short commit>with the whole repository tree. Generatedflake.nixandflake.lockdon't appear in a tarball. - Tasks keep tarballs for the latest 20 updates. Older updates remain in history without a tarball.
- A tarball without
default.nixat the root can work only as a flake input. Task pages show a note for that case.
Binaries¶
Task pages list the substituters and public keys of the project cache in the Binaries row. Hosts with these lines in nix.conf get prebuilt packages. They don't build them.
Verify Deployment¶
Entries in the channel panel include the channel URL, the time since the current update and the latest evaluation of the channel branch. Failed builds leave the channel at the current commit. Counts of failed builds also appear in the channel panel.
gradient task select stable
gradient task channel show
curl https://gradient.example.com/channel/acme/stable/git-revision