Skip to content

buildbot-effects: support flake references for remote repos#585

Open
Mic92 wants to merge 8 commits intomainfrom
flake-flag
Open

buildbot-effects: support flake references for remote repos#585
Mic92 wants to merge 8 commits intomainfrom
flake-flag

Conversation

@Mic92
Copy link
Member

@Mic92 Mic92 commented Feb 26, 2026

Avoids the painful workflow of cloning a repo into a tempdir just to run a one-off effect. Commands now accept Nix flake reference syntax:

buildbot-effects run github:org/repo/branch#my-effect
buildbot-effects list github:org/repo/branch
buildbot-effects list-schedules github:org/repo/branch
buildbot-effects run-scheduled github:org/repo#schedule effect

When a flake ref is detected (by the presence of '#' in the positional arg, or as an optional positional for list commands), we resolve it via nix flake metadata --json to obtain the rev, branch, store path, and locked URL — then pass the locked URL directly to builtins.getFlake instead of constructing a git+file:// URL from a local checkout.

Closes: #584

Avoids the painful workflow of cloning a repo into a tempdir just to
run a one-off effect. Commands now accept Nix flake reference syntax:

  buildbot-effects run github:org/repo/branch#my-effect
  buildbot-effects list github:org/repo/branch
  buildbot-effects list-schedules github:org/repo/branch
  buildbot-effects run-scheduled github:org/repo#schedule effect

When a flake ref is detected (by the presence of '#' in the positional
arg, or as an optional positional for list commands), we resolve it via
`nix flake metadata --json` to obtain the rev, branch, store path, and
locked URL — then pass the locked URL directly to builtins.getFlake
instead of constructing a git+file:// URL from a local checkout.

Closes: #584
When --branch was specified without --rev, effects_args() called
get_git_rev() which always resolves HEAD of the current checkout,
ignoring the requested branch entirely. This meant running:

  buildbot-effects --branch feature run my-effect

would use the rev from whatever branch was checked out, not from
'feature'.

Resolve the rev from the specified branch via git rev-parse when
--branch is given.

Closes: #583
@Mic92 Mic92 force-pushed the flake-flag branch 2 times, most recently from 646fb89 to b3c95cd Compare February 26, 2026 16:05
Store paths from resolved flake references have no .git directory,
causing git_get_tag() et al. to crash. Gate all git fallbacks behind
an _is_git_repo() check.

Also fix options_from_flake_ref: lockedUrl is null for many flake types,
so fall back to the url field which includes the resolved rev.

Move tests/ inside their respective packages to avoid duplicate module
names confusing mypy.
The implementation was just `print("TODO")` and nothing used it.
--secrets only applies to run/run-scheduled, not list/list-schedules.
Move all flags (--rev, --branch, --repo, --path, --debug, --secrets)
from the parent parser to their respective subcommand parsers so
--secrets is only accepted where it makes sense.

Update all internal callers (nix_eval.py, buildbot_effects.py,
scheduled.py) to place flags after the subcommand name.
@Mic92 Mic92 force-pushed the flake-flag branch 2 times, most recently from e98cf42 to 3249532 Compare February 26, 2026 16:36
The effects section in README was getting long and contained outdated
CLI help output. Move it to a dedicated page and update to reflect
the current CLI (flake ref support, subcommand flags, no run-all).
Suppress the 'fatal: not a git repository' message from _is_git_repo()
by redirecting stderr to /dev/null.

Add --add-root gcroot to nix-instantiate calls to silence the
'you did not specify --add-root' warning. The gcroot is kept alive
via a TemporaryDirectory that spans the entire instantiate+run sequence.

Also handle dirtyRev from nix flake metadata for dirty worktrees.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

buildbot-effects: add --flake flag to match nix run syntax

1 participant