Skip to content
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

add no-link, out-link option #40

Merged
merged 1 commit into from
Nov 8, 2023
Merged
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
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ $ nix run github:Mic92/nix-fast-build -- --skip-cached --no-nom --flake ".#check
## Reference

```console
usage: nix-fast-build [-h] [-f FLAKE] [-j MAX_JOBS] [--option name value] [--no-nom] [--systems SYSTEMS]
[--retries RETRIES] [--remote REMOTE] [--always-upload-source] [--no-download]
[--skip-cached] [--copy-to COPY_TO] [--verbose]
[--eval-max-memory-size EVAL_MAX_MEMORY_SIZE] [--eval-workers EVAL_WORKERS]
usage: nix-fast-build [-h] [-f FLAKE] [-j MAX_JOBS] [--option name value] [--remote-ssh-option name value] [--no-nom]
[--systems SYSTEMS] [--retries RETRIES] [--no-link] [--out-link OUT_LINK] [--remote REMOTE]
[--always-upload-source] [--no-download] [--skip-cached] [--copy-to COPY_TO] [--debug]
[--eval-max-memory-size EVAL_MAX_MEMORY_SIZE] [--eval-workers EVAL_WORKERS]

options:
-h, --help show this help message and exit
Expand All @@ -140,21 +140,23 @@ options:
-j MAX_JOBS, --max-jobs MAX_JOBS
Maximum number of build jobs to run in parallel (0 for unlimited)
--option name value Nix option to set
--remote-ssh-option name value
ssh option when accessing remote
--no-nom Don't use nix-output-monitor to print build output (default: false)
--systems SYSTEMS Comma-separated list of systems to build for (default: current system)
--systems SYSTEMS Space-separated list of systems to build for (default: current system)
--retries RETRIES Number of times to retry failed builds
--no-link Do not create an out-link for builds (default: false)
--out-link OUT_LINK Name of the out-link for builds (default: result)
--remote REMOTE Remote machine to build on
--always-upload-source
Always upload sources to remote machine. This is needed if the remote machine cannot
access all sources (default: false)
Always upload sources to remote machine. This is needed if the remote machine cannot access all sources
(default: false)
--no-download Do not download build results from remote machine
--skip-cached Skip builds that are already present in the binary cache (default: false)
--copy-to COPY_TO Copy build results to the given path (passed to nix copy, i.e.
file:///tmp/cache?compression=none)
--verbose Print verbose output
--copy-to COPY_TO Copy build results to the given path (passed to nix copy, i.e. file:///tmp/cache?compression=none)
--debug debug logging output
--eval-max-memory-size EVAL_MAX_MEMORY_SIZE
Maximum memory size for nix-eval-jobs (in MiB) per worker. After the limit is
reached, the worker is restarted.
Maximum memory size for nix-eval-jobs (in MiB) per worker. After the limit is reached, the worker is restarted.
--eval-workers EVAL_WORKERS
Number of evaluation threads spawned
```
27 changes: 25 additions & 2 deletions nix_fast_build/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Options:
copy_to: str | None = None
nom: bool = True
download: bool = True
no_link: bool = False
out_link: str = "result"

@property
def remote_url(self) -> None | str:
Expand Down Expand Up @@ -158,6 +160,17 @@ async def parse_args(args: list[str]) -> Options:
default=0,
help="Number of times to retry failed builds",
)
parser.add_argument(
"--no-link",
help="Do not create an out-link for builds (default: false)",
action="store_true",
default=False,
)
parser.add_argument(
"--out-link",
help="Name of the out-link for builds (default: result)",
default="result",
)
parser.add_argument(
"--remote",
type=str,
Expand Down Expand Up @@ -252,6 +265,8 @@ async def parse_args(args: list[str]) -> Options:
eval_max_memory_size=a.eval_max_memory_size,
eval_workers=a.eval_workers,
copy_to=a.copy_to,
no_link=a.no_link,
out_link=a.out_link,
)


Expand Down Expand Up @@ -464,7 +479,7 @@ async def build(
self, stack: AsyncExitStack, build_output: IO[str], opts: Options
) -> int:
proc = await stack.enter_async_context(
nix_build(self.drv_path, build_output, opts)
nix_build(self.attr, self.drv_path, build_output, opts)
)
rc = 0
for _ in range(opts.retries + 1):
Expand Down Expand Up @@ -562,13 +577,21 @@ async def get_context(self) -> AsyncIterator[T]:

@asynccontextmanager
async def nix_build(
installable: str, stderr: IO[Any] | None, opts: Options
attr: str, installable: str, stderr: IO[Any] | None, opts: Options
) -> AsyncIterator[Process]:
args = [
"nix-build",
installable,
"--keep-going",
] + opts.options
if opts.no_link:
args += ["--no-link"]
else:
args += [
"--out-link",
opts.out_link + "-" + attr,
]

args = maybe_remote(args, opts)
logger.debug("run %s", shlex.join(args))
proc = await asyncio.create_subprocess_exec(*args, stderr=stderr)
Expand Down