diff --git a/README.md b/README.md index 4b28e5c1a..a6847e842 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/buildbot_nix/buildbot_nix/__init__.py b/buildbot_nix/buildbot_nix/__init__.py index 4b7414151..ef2f6a0ac 100644 --- a/buildbot_nix/buildbot_nix/__init__.py +++ b/buildbot_nix/buildbot_nix/__init__.py @@ -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" diff --git a/buildbot_nix/buildbot_nix/repo_config/__init__.py b/buildbot_nix/buildbot_nix/repo_config/__init__.py index 59591fc1c..e32e4b647 100644 --- a/buildbot_nix/buildbot_nix/repo_config/__init__.py +++ b/buildbot_nix/buildbot_nix/repo_config/__init__.py @@ -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 @@ -18,6 +21,7 @@ class RepoConfig(BaseModel): class BranchConfig(BaseModel): + flake_dir: str = "." lock_file: str = "flake.lock" attribute: str = "checks" @@ -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