Skip to content

add flake_dir to per repo config #450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ options.
| :-------- | :---------- | :---- | :-------------------------------------------------------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| lock file | `lock_file` | `str` | dictates which lock file `buildbot-nix` will use when evaluating your flake | `flake.lock` | have multiple lockfiles, one for `nixpkgs-stable`, one for `nixpkgs-unstable` or by default pin an input to a private repo, but have a lockfile with that private repo replaced by a public repo for CI |
| attribute | `attribute` | `str` | which attribute in the flake to evaluate and build | `checks` | using a different attribute, like `hydraJobs` |
| flake_dir | `flake_dir` | `str` | which directory the flake is located | `.` | using a different flake, like `./tests` |

## Binary caches

Expand Down
2 changes: 1 addition & 1 deletion buildbot_nix/buildbot_nix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ async def run(self) -> int:
"--force-recurse",
"--check-cache-status",
"--flake",
f".#{branch_config.attribute}",
f"{branch_config.flake_dir}#{branch_config.attribute}",
*(
["--reference-lock-file", branch_config.lock_file]
if branch_config.lock_file != "flake.lock"
Expand Down
12 changes: 11 additions & 1 deletion buildbot_nix/buildbot_nix/repo_config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import tomllib
from pathlib import Path
from tomllib import TOMLDecodeError
from typing import TYPE_CHECKING, Self

from buildbot.process.buildstep import BuildStep, ShellMixin
from pydantic import BaseModel, ValidationError

from buildbot_nix.errors import BuildbotNixError

if TYPE_CHECKING:
from buildbot.process.log import StreamLog

Expand All @@ -18,6 +21,7 @@ class RepoConfig(BaseModel):


class BranchConfig(BaseModel):
flake_dir: str = "."
lock_file: str = "flake.lock"
attribute: str = "checks"

Expand All @@ -43,10 +47,16 @@ async def extract_during_step(cls, buildstep: BuildStepShellMixin) -> Self:
)
return cls()
try:
return cls.model_validate(tomllib.loads(cmd.stdout))
config = cls.model_validate(tomllib.loads(cmd.stdout))
flake_dir = Path(config.flake_dir).resolve()
root_dir = Path.cwd().resolve()
if ":" in config.flake_dir or not flake_dir.is_relative_to(root_dir):
msg = f"Invalid flake_dir {config.flake_dir}"
raise BuildbotNixError(msg)
except ValidationError as e:
stdio.addStderr(f"Failed to read repository local configuration, {e}.\n")
return cls()
except TOMLDecodeError as e:
stdio.addStderr(f"Failed to read repository local configuration, {e}.\n")
return cls()
return config