Declarative State¶
The options below services.gradient.state come from nix/modules. To work through the setup, read Manage Gradient with Nix. For the model behind this approach, see Declarative State.
services.gradient.state = {
users.alice = { email = "alice@example.com"; password_file = "/run/secrets/alice-password"; };
projects.acme = { created_by = "alice"; private_key_file = "/run/secrets/acme-ssh-key"; };
caches.main = { created_by = "alice"; signing_key_file = "/run/secrets/main-cache-key"; projects = [ "acme" ]; };
tasks.web-app = { project = "acme"; created_by = "alice"; repository = "https://github.com/acme/web-app"; };
};
General¶
| Option | Type | Default | Description |
|---|---|---|---|
api_keys |
attrs of submodule | { } |
API keys, one entry per key name. |
caches |
attrs of submodule | { } |
Caches, one entry per cache name. |
delete |
bool | true |
Users, projects and caches that the declaration doesn't include undergo deletion by this option. Deleted users become disabled and lose superuser status in false. Deletions of API keys always remove those keys. |
git_host_connections |
attrs of submodule | { } |
Connections to Git hosts. One entry per connection. |
projects |
attrs of submodule | { } |
Projects, one entry per project name. |
roles |
attrs of submodule | { } |
Custom roles, one entry per role name. |
tasks |
attrs of submodule | { } |
Tasks, one entry per task name. |
teams |
attrs of submodule | { } |
Teams, one entry per team name. |
users |
attrs of submodule | { } |
Users, one entry per user name. |
validate |
bool | true |
Validation of the generated state at build time through the server's --state-validate. Schema and reference errors then fail the Nix build instead of the first server start. |
workers |
attrs of submodule | { } |
Worker registrations, one entry per worker ID. |
users.<name>¶
| Option | Type | Default | Description |
|---|---|---|---|
email |
string | - | Email address of the user. |
email_verified |
bool | true |
Whether the user's email address is verified. |
existing_account_id |
null or string | null |
Declared users take over an existing account with this UUID (signup, SCIM, external sign-in). The takeover deletes the account's password, sessions, undeclared API keys, external ID links and SCIM external ID. Servers skip this user and log an error on conflict of a username or email with such an account without the option. |
name |
string | username |
Full name of the user. |
password_file |
null or string | null |
File containing the hashed password. |
superuser |
bool | false |
Whether the user is a superuser. |
username |
string | attribute name | Unique user name. |
projects.<name>¶
| Option | Type | Default | Description |
|---|---|---|---|
created_by |
string | - | Name of the user who created the project. |
description |
null or string | null |
Free-text description of the project. |
display_name |
string | name |
Name shown for the project in the UI. |
git_https_credentials |
list of submodule | [ ] |
Credentials for cloning Git repositories over HTTPS. One entry per host. State apply operations delete a credential that is no longer in this list at the next apply. The REST API does not allow creating, changing or deleting credentials for projects managed by declarative state. |
git_https_credentials.*.host |
string | - | A bare hostname with an optional port (for example github.com or git.example.com:8443). URLs, usernames, paths and IPv6 addresses are invalid. |
git_https_credentials.*.password_file |
string | - | File with a password or access token. Passwords stay encrypted on the server. |
git_https_credentials.*.username |
string | - | The username on the host. Forges that authenticate with a token accept any non-empty name in many cases. Examples include x-access-token on GitHub and oauth2 on GitLab. |
allow_exec_in_build_requests |
bool | false |
Build requests from gradient build and gradient run start exec jobs that match them. Instance and worker switches still apply. These exec jobs get project secrets and project SSH keys. The exception is a build request from an exec job of a pull request from a fork without maintainer approval. |
hide_build_requests |
bool | false |
Set to true to keep the project's automatic build-request task out of task listings in the web UI. |
id |
null or string | null |
UUID of the project. Declared values allow a rename of the existing project on a name change. Missing values lead to removal of the old project and creation of a new project on the server. Values that conflict with an existing project of the same name meet rejection from the server. |
members |
list of submodule | [ ] |
Users that hold a role on the project. |
members.*.role |
string | - | Role assigned to the user: one of the built-in Admin, Write or View, or a custom role declared for this project in state.roles. |
members.*.user |
string | - | Name of the user to add as a member, declared in state.users. |
name |
string | attribute name | Unique name of the project. |
owner_team |
null or string | null |
Team with ownership of the project. Grants for that project come from the team's new_projects settings. |
private_key_file |
string | - | Path to the SSH private key used for Git access. |
public |
bool | false |
Set to true to make the project visible to all users. |
secret_files |
attrs of string | { } |
Files with the project secrets of exec jobs, one entry per secret name. The stored values stay encrypted. Secrets that leave this list vanish on the next state apply. Secrets set through the API stay untouched. |
teams |
list of submodule | [ ] |
Teams with access to the project. Team grants declared here and later removed from the list get cleaned up on the next state apply. Grants created through the API or by new-project settings remain untouched. |
teams.*.role |
null or string | null |
Role given to the team's users: one of the built-in Admin, Write or View, or a custom role of this project. Required when users is true. |
teams.*.team |
string | - | Name of the team to grant on the project. |
teams.*.users |
bool | true |
Set to true to give the team's users role on the project. |
teams.*.workers |
bool | true |
Set to true to let the team's workers pick up jobs from the project. |
tasks.<name>¶
| Option | Type | Default | Description |
|---|---|---|---|
actions |
list of submodule | [ ] |
Actions for this task are email notifications, web requests, Matrix and Slack messages and pull request automation. |
actions.*.active |
bool | true |
Whether this action is active. |
actions.*.config |
attribute set | { } |
Configuration specific to the action type. |
actions.*.events |
list of string | [ ] |
Events this action subscribes to. |
actions.*.name |
string | - | Action name, unique within the task. |
actions.*.type |
one of send_mail send_web_request send_matrix_message send_slack_message open_pr start_evaluation |
- | The kind of action, which determines the expected config. |
active |
bool | true |
Whether this task is active. |
concurrency |
one of auto hard_abort soft_abort skip all |
"auto" |
What happens when a new trigger event arrives while an evaluation of the same branch is still running, see concurrency. |
created_by |
string | - | User name of the task's creator. |
description |
null or string | null |
Description of the task. |
display_name |
string | name |
Name of the task shown in the UI. |
exec_enabled |
bool | false |
Set to true to start exec jobs of the task. Exec entry points of a task without it fail with a message. |
extra_allowed_uri_prefixes |
list of string | [ ] |
URL prefixes this task can fetch during evaluation. They add to the URL prefixes that locked flake inputs and the server allow. Prefixes match the same URL or a URL under it at the / position. Entries like github: allow a whole URL scheme. Nothing changes when restrict_evaluation_fetches is false. |
flake_input_overrides |
attrs of submodule | { } |
Overrides applied when fetching flake inputs, with one entry per input name. |
flake_input_overrides.<name>.keep_url |
bool | false |
Whether to force-update this input from its flake-declared URL. |
flake_input_overrides.<name>.url |
null or string | null |
Flake reference that replaces this input. |
git_host_connection |
null or string | null |
Name of the connection for the Git host of a task. Lookup order is the task's project first, then the team for the project, then the instance. Push triggers, pull request triggers and report_status use this name. Team and instance connections get a repository grant for exactly the task repository. The grant and the task disappear at the same time. Gradient won't select or link a connection automatically for declared tasks. Declared values override the UI and API. |
id |
null or string | null |
UUID of the task. Declare a value to rename an existing task by changing its name. Evaluation and triggers carry over. Keep the task in that project. |
keep_evaluations |
int | 30 |
Finished evaluations stay regardless of result, up to this number. Active evaluations don't block GC and don't count toward this number. Aborted evaluations go first during GC, then the oldest evaluations. The most recent evaluation and the most recent completed evaluation always stay, even above this number. Set this number in the range 1 to eval.maxKeep. |
multi_node_evaluation |
bool | false |
Whether more than one eval worker may evaluate one evaluation of this task together. The server can split an evaluation only when past evaluations predict a gain. |
name |
string | attribute name | Unique name of the task. |
only_evaluate |
bool | false |
Set to true to evaluate the task only. Evaluations end after evaluation. No build. No exec jobs run. |
project |
string | - | Name of the project that owns this task. |
report_status |
bool | false |
Whether to post commit statuses for evaluation and build to the Git host. Requires git_host_connection with reports_status = true. |
repository |
string | - | Git repository URL of the task. |
restrict_evaluation_fetches |
bool | false |
Evaluate this task with Nix restrict-eval. Fetches during evaluation (builtins.fetchTree, fetchurl, fetchTarball, fetchGit) can access only the inputs locked in flake.lock, the URL prefixes in the server allowlist and extra_allowed_uri_prefixes. Set false to let the task fetch any URL during evaluation. |
retry_failed_builds |
bool | true |
Whether a new evaluation of this task re-queues its permanently failed builds and their dependents. With false, they remain failed until a user retries the build or the evaluation. |
wait_for_workers |
bool | false |
Whether to wait for workers when an evaluation can require an architecture or system feature that no connected worker can offer for its builds. The server can abort that evaluation and show a warning about what is missing when this field is absent. Exec jobs that no connected worker can run have the same behavior. |
triggers |
null or list of submodule | null |
Evaluation triggers of the task are polling, push to a Git host, pull request on a Git host, cron schedule or POST request. |
triggers.*.active |
bool | true |
Whether this trigger is active. |
triggers.*.config |
submodule | { } |
Configuration for a specific trigger type. Keys come from Trigger Types. Unknown keys and values of the wrong type, such as a string for branches, cause Nix evaluation to fail. |
triggers.*.id |
null or string | null |
The UUID of the trigger, and the <id> in post_request trigger URL /api/v1/hooks/trigger/<id>. The server can generate a UUID with null. Without a fixed ID, the URL can change on each trigger recreation by state apply after a config change. The server can reject an ID of another task, or an ID for a config with another ID already set. |
triggers.*.is_default |
bool | false |
Whether the trigger is the default trigger of the task. The first trigger is the default when no trigger sets the flag. |
triggers.*.secret_file |
null or path | null |
Path to a file with the trigger secret. The post_request type needs this path. Other types reject it. An empty file can make state apply fail. |
triggers.*.type |
one of polling reporter_push reporter_pull_request time post_request |
- | The kind of trigger, which determines the expected config and how the trigger fires. |
wildcard |
string | "packages.x86_64-linux.**" |
Comma-separated Nix attribute paths to evaluate from the flake. A * segment matches any attribute name, ** also matches a nested set below it, and x86_64-* matches part of a name. A pattern prefixed with ! excludes matching paths. See Evaluation Wildcards. |
git_host_connections.<name>¶
| Option | Type | Default | Description |
|---|---|---|---|
access_token_file |
null or path | null |
Path to a file with an API token for the git host. Needed to post commit statuses and create pull requests. |
account_login |
null or string | null |
The GitHub user or organization that has the App installed. Required for git_host_type = "github". Only repositories of this account fit this connection. |
base_url |
null or string | null |
Base URL for the Git host API (for example, https://gitea.example.com). A GitLab connection without base_url uses https://gitlab.com. |
created_by |
string | - | Name of the user who created the connection. |
display_name |
null or string | null |
A human-readable name to display for the connection. |
git_host_type |
one of gitea forgejo gitlab github |
- | Type of Git host |
id |
null or string | null |
The UUID of the connection. The webhook URL /api/v1/hooks/<id> can end with this value. The server can generate a UUID with null. The server can reject a conflicting value for an existing connection of the same name. |
installation_id |
null or int | null |
The installation ID of the GitHub App. This number shows at the end of the installation URL. The field is required for git_host_type = "github" and allowed only with owner = "instance". |
name |
string | attribute name | Name of the connection. Unique per owner. |
owner |
string | - | instance, team/<name> or project/<name>. Tasks can use instance and team connections only with a repository grant. Team connections stay limited to projects of the team. A Gitea or Forgejo connection needs base_url. |
receives_events |
bool | true |
Whether the connection can receive webhooks from the Git host with HMAC verification. Triggers for push and pull requests need this. |
reports_status |
null or bool | null |
Whether the connection can post commit statuses to the Git host. Tasks that use report_status need this setting. null means true on github and false on other Git hosts. |
secret_file |
null or path | null |
Path to the file with the secret for HMAC signatures on incoming webhooks. |
Rejected Connection Settings¶
These declarations stop the Nix build during validation. Server-side checks at state apply also reject them.
| Declaration | Fix |
|---|---|
git_host_type = "github" without account_login |
Set account_login to the GitHub account of the installation. |
git_host_type gitea, forgejo or gitlab without secret_file |
Set secret_file. A connection for commit status only can set receives_events = false instead. |
Task with a repository on a host other than the base_url host of its git_host_connection |
Choose the connection for the host of the repository, or correct base_url. |
caches.<name>¶
| Option | Type | Default | Description |
|---|---|---|---|
active |
bool | true |
Cache activity flag. The UI can change this value, and the server restores it on the next start. |
created_by |
string | - | Name of the user who created the cache. |
description |
null or string | null |
Cache description. |
display_name |
string | name |
Name shown in the UI for this cache. |
id |
null or string | null |
Cache UUID. Renames that use an existing UUID preserve the cache and stored paths. Renames with a new UUID create a new cache instead. The cache URL and the name of the signing key change with the name. |
local_priority |
null or int | null |
Priority written to nix-cache-info for clients inside http.localIps. |
max_storage_gb |
int | 0 |
Storage limit for the cache, in GB. |
members |
list of submodule | [ ] |
Users with a direct role on this cache. |
members.*.role |
string | - | Role assigned to the user: one of the built-in Admin, Write, View, or a custom role defined on this cache. |
members.*.user |
string | - | User name, resolved during state application. |
name |
string | attribute name | Unique name of the cache. |
owner_team |
null or string | null |
The team in charge of the cache. Cache admins can add members of that team without an invitation. |
priority |
int | 10 |
Priority written to nix-cache-info. Nix queries caches with lower values first. |
projects |
list of string or submodule | [ ] |
Projects that subscribe to this cache (project names or submodules). Plain names subscribe with ReadWrite and signed outputs. The Web UI and API can't change or delete these subscriptions. |
projects.*.mode |
one of ReadWrite ReadOnly WriteOnly |
"ReadWrite" |
Three access modes exist for a subscription. ReadWrite can pull and push, while ReadOnly can pull only. WriteOnly can push only. |
projects.*.name |
string | - | Name of the subscribed project. |
projects.*.sign_outputs |
null or bool | null |
Use the cache key to sign the outputs that projects push to this cache. External Nix clients don't trust unsigned store paths. Values of null take the project mode, with true in ReadWrite and WriteOnly and false in ReadOnly. Validation rules reject the combination of ReadOnly and true. |
pull_through |
bool | true |
Whether this cache serves paths from its upstream caches to Nix clients. |
public |
bool | false |
Whether every project can use this cache. |
teams |
list of submodule | [ ] |
Teams with a grant on this cache. Grants declared here but removed from the list get revoked on the next state apply. Grants made through the API remain untouched. |
teams.*.role |
string | - | Role given to the team's users: Admin, Write, View, or a custom role defined on this cache. |
teams.*.team |
string | - | Team that receives the grant. |
roles |
list of submodule | [ ] |
Custom roles defined on this cache. |
roles.*.name |
string | - | Name of the custom role, distinct from the built-in roles. |
roles.*.permissions |
list of string | [ ] |
Cache permissions granted by the role: viewCache, readStore, writeStore, manageCacheSettings, manageCacheKeys, manageUpstreamCaches, manageCacheMembers, manageCacheRoles, manageCacheSubscriptions, manageCacheWebhooks or deleteCache. |
signing_key_file |
string | - | Path to the file with the Nix cache signing key. |
upstream_caches |
list of submodule | cache.nixos.org | Upstream caches used as substituters: internal Gradient caches or external Nix binary caches. |
upstream_caches.*.active |
boolean | true |
Whether the upstream cache is in use. Gradient keeps inactive upstream caches but never queries them. The UI can change this value and the server restores it on the next start. |
upstream_caches.*.basic_auth_password_file |
null or string | null |
A file with the password for HTTP basic auth on an external Nix binary cache. Set it together with basic_auth_user. systemd loads it as credential gradient_cache_upstream_<cache>_<index>_password. <index> is the position in upstream_caches. Positions start at 0 and include internal entries. |
upstream_caches.*.basic_auth_user |
null or string | null |
Username for HTTP basic authentication with an external Nix binary cache. The username cannot include :. The username is valid only on https:// URLs. |
upstream_caches.*.bearer_token_file |
null or string | null |
A file with a bearer token for an external Nix binary cache, in place of basic auth. Gradient does read the file as a systemd credential gradient_cache_upstream_<cache>_<index>_bearer_token. The token is valid only for https:// URLs. |
upstream_caches.*.cache_name |
null or string | null |
Name of the internal Gradient cache to use. All internal upstream caches need this value. |
upstream_caches.*.display_name |
null or string | null |
Name shown in the UI for the upstream cache. Each external upstream cache needs this value. |
upstream_caches.*.http1_only |
boolean | false |
Whether requests to the external Nix binary cache use HTTP/1.1 only. Enable this for caches that break HTTP/2 transfers. |
upstream_caches.*.mode |
one of ReadWrite ReadOnly WriteOnly |
"ReadWrite" |
Access mode for an internal upstream cache. |
upstream_caches.*.public_key |
null or string | null |
Public key of the external Nix binary cache. Required for external upstream caches. |
upstream_caches.*.type |
one of internal external |
- | Kind of upstream: internal for another Gradient cache, external for a Nix binary cache URL. |
upstream_caches.*.url |
null or string | null |
URL of an external Nix binary cache. Always set this value on each external upstream cache. |
roles.<name>¶
| Option | Type | Default | Description |
|---|---|---|---|
name |
string | attribute name | Role name. Unique within the project and distinct from the built-in roles Admin, Write and View. |
permissions |
list of string | [ ] |
Permissions granted by the role. Each entry is a camelCase identifier. Shell, console, port forwarding and SSH logins in exec jobs need openJobTerminal. |
project |
string | - | Project that owns the role. |
api_keys.<name>¶
| Option | Type | Default | Description |
|---|---|---|---|
key_file |
string | - | Path to a file that hold the SHA-256 hash of the API token. The hash use lowercase hex and omit the GRAD prefix. |
name |
string | attribute name | Name of this API key. |
owned_by |
string | - | Name of the user who own this key. |
cache_permissions |
list of string | [ ] |
A key can receive cache permissions viewCache, readStore, writeStore, manageCacheSettings, manageCacheKeys, manageUpstreamCaches, manageCacheMembers, manageCacheRoles, manageCacheSubscriptions, manageCacheWebhooks or deleteCache. The key can get these permissions on every cache where the owner of the key has a role. The role of the owner in that cache can limit those permissions. Only keys with project = null can have cache permissions. |
permissions |
list of string | [ ] |
Permissions this key grant, written as camelCase identifiers such as viewProject, triggerEvaluation, editTask or manageMembers. Keep at least one of permissions and cache_permissions non-empty. Sets of Gradient permissions always contain viewProject. The key can create projects through createProject only with project = null. The key can use the owner's superuser privileges only if project = null is present and superuser = true is available to the owner. GET, HEAD and OPTIONS requests pass through readSuperuser. All other requests pass through writeSuperuser. The shell, console and port forward of exec jobs need openJobTerminal. |
project |
null or string | null |
Project to which this key restrict access. null mean no restriction. |
teams.<name>¶
| Option | Type | Default | Description |
|---|---|---|---|
display_name |
string | attribute name | Name of the team shown in the UI. |
members |
list of submodule | [ ] |
Users belonging to the team. A member declared here but removed from the list leaves the team on the next state apply. Members added through the API, an OIDC group or a SCIM group remain untouched. |
members.*.role |
one of Admin Member |
"Member" |
Role of the member in the team. Admins can manage members, workers, grants and requests. |
members.*.user |
string | - | Name of the user, resolved at state apply time. |
name |
string | attribute name | Name of the team. A team managed here has its settings locked in the API, while other members and workers can still join through the API. |
new_projects.role |
null or one of Admin Write View |
null |
Project role that a team can grant to its users on projects that belong to that team. |
new_projects.users |
bool | false |
Team users receive new_projects.role on projects that belong to the team with this option on. UI screens show this as "Default role of members on team projects". |
new_projects.workers |
bool | false |
Turn this on to grant permission to this team's workers on every new project, regardless of project ownership. |
oidc_group |
null or string | null |
OIDC group whose members join the team at sign-in. They leave the team once the group no longer appears in their groups claim. The groups scope must be enabled. |
scim_group |
null or string | null |
SCIM group mapped to the team's members. |
workers.<name>¶
Each worker registration has the following options.
| Option | Type | Default | Description |
|---|---|---|---|
created_by |
null or string | null |
Name of the user who created the registration. |
display_name |
string | attribute name | Name shown for the worker in the UI. |
enable_build |
bool | true |
Grant of the worker's build capability by the server. |
enable_eval |
bool | true |
Grant of the worker's eval capability by the server. |
enable_exec |
bool | false |
Grant of the worker's exec capability by the server. |
enable_network |
bool | true |
Grant of the worker's network capability by the server. |
enable_secrets |
bool | true |
Grant of the worker's secrets capability by the server. |
enabled |
bool | true |
Activation state of the worker. UI changes persist only until the next server start. |
projects |
list of string | [ ] |
Projects under which the worker registered, one registration per project. An empty list marks a team worker. |
team |
null or string | null |
Owning team. A team worker can build for every project that grants the team's workers. Cannot be combined with projects. |
token_file |
path | - | File with the worker's authentication token. |
url |
null or string | null |
WebSocket URL where the worker accepts server connections. |
worker_id |
string | - | Identity of the worker. |
Trigger Types¶
type |
Connection | config |
|---|---|---|
polling |
- | interval_secs (minimum 10, default 300) and branch (default: the remote HEAD), include_paths and exclude_paths (default [ ]: path patterns that limit triggers to commits that change specific files. See Path Filters for details) |
reporter_push |
Task connection with receives_events |
branches, tags (glob, an empty value can match all), releases_only, include_flake_inputs (default false: a push to the repository of a tracked flake input can start an input update, see Pushes to Flake Inputs), include_paths and exclude_paths (default [ ]: path patterns that limit triggers to commits that change specific files. See Path Filters for details) |
reporter_pull_request |
Task connection with receives_events |
branches, actions (default opened, synchronize, reopened), require_approval (default true: pull requests from non-writers wait for a maintainer's approval), include_paths and exclude_paths (default [ ]: path patterns that limit triggers to commits that change specific files. See Path Filters for details) |
time |
- | cron is in UTC. Two forms exist. One form is 5 fields for min hour dom mon dow (seconds are 0). The other form is 6 fields for sec min hour dom mon dow. An example is "0 2 * * *". branch (default: remote HEAD). |
post_request |
- | branch (default: the remote HEAD), include_paths and exclude_paths (default [ ]: path patterns that limit triggers to commits that change specific files. See Path Filters for details). Send a POST request to /api/v1/hooks/trigger/<id> with the trigger secret to fire the trigger. Read the secret from secret_file. |
Trigger rules, cron syntax and pull request commands are in Triggers.
triggers = null leaves the current triggers in place. New tasks without a triggers key start with a polling trigger as the default. An empty list or two default triggers count as invalid configuration.
Action Types¶
type |
events |
config |
|---|---|---|
send_mail |
Required | recipients, subject_template |
send_web_request |
Required | url, token_file |
send_matrix_message |
Required | homeserver, room_id, access_token_file |
send_slack_message |
Required | webhook_url_file |
open_pr |
Empty | git_host_connection, generator, granularity, verify_gate, branch_pattern, title_template, body_template, update_existing, see Update Flake Inputs. generator is flake_lock (default) or exec_tree for the gradient/tree.patch output of an exec job |
start_evaluation |
Required | task: a task of the same project, evaluated at its head commit |
Event names live in the events reference.