Skip to content

Commit

Permalink
Use separate nix path for the remote server
Browse files Browse the repository at this point in the history
  • Loading branch information
z8v committed Aug 23, 2023
1 parent 375f687 commit 9d80067
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions core/nixpkgs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -396,21 +396,27 @@ def _nixpkgs_build_file_content(repository_ctx):
else:
return None

def _nixpkgs_build_and_symlink(repository_ctx, nix_path, expr_args, build_file_content):
def _nixpkgs_build_and_symlink(repository_ctx, nix_build, build_file_content):
# Large enough integer that Bazel can still parse. We don't have
# access to MAX_INT and 0 is not a valid timeout so this is as good
# as we can do. The value shouldn't be too large to avoid errors on
# macOS, see https://github.com/tweag/rules_nixpkgs/issues/92.
timeout = 8640000
repository_ctx.report_progress("Building Nix derivation")

nix_path = executable_path(
repository_ctx,
"nix",
extra_msg = "See: https://nixos.org/nix/",
)

nix_host = repository_ctx.os.environ.get('BAZEL_NIX_REMOTE', '')
if nix_host:
nix_store = "ssh-ng://{host}?max-connections=1".format(host = nix_host)
repository_ctx.report_progress("Remote-building Nix derivation")
exec_result = execute_or_fail(
repository_ctx,
[nix_path, "build", "--store", nix_store, "--eval-store", "auto"] + expr_args,
[nix_path, "build", "--store", nix_store, "--eval-store", "auto"],
failure_message = "Cannot build Nix attribute '{}'.".format(
repository_ctx.attr.attribute_path,
),
Expand Down Expand Up @@ -440,7 +446,7 @@ def _nixpkgs_build_and_symlink(repository_ctx, nix_path, expr_args, build_file_c

exec_result = execute_or_fail(
repository_ctx,
[nix_path, "build"] + expr_args,
nix_build,
failure_message = "Cannot build Nix derivation for package '@{}'.".format(repository_ctx.name),
quiet = repository_ctx.attr.quiet,
timeout = timeout,
Expand Down Expand Up @@ -574,13 +580,15 @@ def _nixpkgs_package_impl(repository_ctx):
for opt in repository_ctx.attr.nixopts
])

nix_path = executable_path(
nix_build_path = executable_path(
repository_ctx,
"nix",
"nix-build",
extra_msg = "See: https://nixos.org/nix/",
)

_nixpkgs_build_and_symlink(repository_ctx, nix_path, expr_args, build_file_content)
nix_build = [nix_build_path] + expr_args

_nixpkgs_build_and_symlink(repository_ctx, nix_build, build_file_content)

_nixpkgs_package = repository_rule(
implementation = _nixpkgs_package_impl,
Expand Down Expand Up @@ -777,8 +785,9 @@ def _nixpkgs_flake_package_impl(repository_ctx):
"nix",
extra_msg = "See: https://nixos.org/nix/",
)
nix_build = [nix_path, "build"] + expr_args

_nixpkgs_build_and_symlink(repository_ctx, nix_path, expr_args, build_file_content)
_nixpkgs_build_and_symlink(repository_ctx, nix_build, build_file_content)

_nixpkgs_flake_package = repository_rule(
implementation = _nixpkgs_flake_package_impl,
Expand Down

0 comments on commit 9d80067

Please sign in to comment.