Skip to content

Commit a8d4305

Browse files
committed
add flake_dir to per repo config
1 parent 47ad4c7 commit a8d4305

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ options.
225225
| :-------- | :---------- | :---- | :-------------------------------------------------------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
226226
| 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 |
227227
| attribute | `attribute` | `str` | which attribute in the flake to evaluate and build | `checks` | using a different attribute, like `hydraJobs` |
228+
| flake_dir | `flake_dir` | `str` | which directory the flake is located | `.` | using a different flake, like `./tests` |
228229

229230
## Binary caches
230231

buildbot_nix/buildbot_nix/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ async def run(self) -> int:
176176
"--force-recurse",
177177
"--check-cache-status",
178178
"--flake",
179-
f".#{branch_config.attribute}",
179+
f"{branch_config.flake_dir}#{branch_config.attribute}",
180180
*(
181181
["--reference-lock-file", branch_config.lock_file]
182182
if branch_config.lock_file != "flake.lock"

buildbot_nix/buildbot_nix/repo_config/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import tomllib
2+
from pathlib import Path
23
from tomllib import TOMLDecodeError
34
from typing import TYPE_CHECKING, Self
45

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

9+
from buildbot_nix.errors import BuildbotNixError
10+
811
if TYPE_CHECKING:
912
from buildbot.process.log import StreamLog
1013

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

1922

2023
class BranchConfig(BaseModel):
24+
flake_dir: str = "."
2125
lock_file: str = "flake.lock"
2226
attribute: str = "checks"
2327

@@ -43,10 +47,16 @@ async def extract_during_step(cls, buildstep: BuildStepShellMixin) -> Self:
4347
)
4448
return cls()
4549
try:
46-
return cls.model_validate(tomllib.loads(cmd.stdout))
50+
config = cls.model_validate(tomllib.loads(cmd.stdout))
51+
flake_dir = Path(config.flake_dir).resolve()
52+
root_dir = Path.cwd().resolve()
53+
if ":" in config.flake_dir or not flake_dir.is_relative_to(root_dir):
54+
msg = f"Invalid flake_dir {config.flake_dir}"
55+
raise BuildbotNixError(msg)
4756
except ValidationError as e:
4857
stdio.addStderr(f"Failed to read repository local configuration, {e}.\n")
4958
return cls()
5059
except TOMLDecodeError as e:
5160
stdio.addStderr(f"Failed to read repository local configuration, {e}.\n")
5261
return cls()
62+
return config

0 commit comments

Comments
 (0)