Skip to content

Update Flake Inputs

Pull requests carry flake.lock bumps. Successful builds of the updated flake precede them.

Requirements:

1. Track the Inputs

On the task, go to Settings -> Flake Inputs -> New Override. Fill in the Input Name and turn on Force update using the URL declared in flake.nix.

services.gradient.state.tasks.web-app.flake_input_overrides = {
  nixpkgs.keep_url = true;
  "home-manager*".keep_url = true; # (1)!
};
  1. * and ? act as wildcards across input names. A bare * tracks every input.

Supported input types: github, gitlab and git, including git over SSH with the project's SSH key.

Warning

An override with a URL pins that input at the given address. No update round of the task can run while pins exist. No pull request can land while the pin is in place.

2. Add the PR Action

Open [Actions] -> [New Action] in the task. Choose PR as the type. Select the connection for the Git host. Default settings work for most repositories.

Do the same as GitHub guide and declare the github-acme connection first.

services.gradient.state.tasks.web-app.actions = [{
  name = "flake-update";
  type = "open_pr";
  config.git_host_connection = "github-acme";
}];
Field Default Effect
Granularity per_run With per_input, one pull request gets opened per input rather than a single one for all inputs
Verify Gate build With eval or none, the pull request opens after evaluation of the updated flake, before builds complete
Branch Pattern gradient/flake-lock-update With per_input, {input} must appear in the pattern
Title Template flake.lock: update <inputs> Accepts the placeholders {input}, {inputs}, {count}
Body Template Old and new revision for each input Accepts the same placeholders as the title
Update existing PR on An open pull request gets refreshed instead of a second one being opened

Update Run

  • A trigger fire and a Fire Now click start the update evaluation alone.
  • Click Run to start an update evaluation alongside the normal evaluation.
  • Only a Push trigger with include_flake_inputs can start update evaluation on a push to the repository of a tracked input. See Pushes to Flake Inputs.
flowchart LR
    bump[Bump tracked inputs] --> verify[Evaluate and build] --> pr[Open or update the PR]
  • Force updates from Gradient go through the Git host connection of the open_pr action. These updates set each branch to the current base branch plus one new commit. Branch protection on the Git host is the only guard for a branch.
  • Pull requests never lag behind.
  • Unchanged flake.lock files trigger no pull request.
  • A failed build with the default build check blocks pull request creation.

Update in an Exec Job

Updates can run as a script in exec job. Optional checks can run before the pull request. The PR action from Step 2 can open the pull request through a connection to the Git host. Step 1 can stay unused.

# flake.nix
apps.x86_64-linux.update = {
  type = "app";
  program = "${pkgs.writeShellScript "update" ''
    nix flake update
    gradient build 'nixosConfigurations.*.config.system.build.toplevel' # (1)!
    gradient pr open --title "flake: update inputs" --branch update/flake flake.lock
  ''}";
  passthru.gradient = { network = true; };
};
  1. A failed build can end the script before the pull request.

A loop can create one pull request per input.

for input in $(nix flake metadata --json | jq -r '.locks.nodes.root.inputs | keys[]'); do
  nix flake update "$input"
  gradient build && gradient pr open --title "update $input" --branch "update/$input" flake.lock
  git checkout -- flake.lock
done
  • Choose the exec job for custom checks or one pull request per input. Use the PR action for a plain lock bump.
  • gradient pr open and job token: Open Pull Requests.

Verify Deployment

  • Use the Run button on the task to run a second evaluation of the update.
  • Pull request bodies carry the old revision and the new revision of each input.

Next Steps