Skip to content

Commit

Permalink
Fail when nixpkgs_package output is a single file
Browse files Browse the repository at this point in the history
This closes tweag#99.

Currently we do not support single file as bazel external repository.
However if user try it by mistake it fails with "could not create
symlink, file already exists".

This change introduces a more detailled error.
  • Loading branch information
guibou committed Dec 2, 2019
1 parent 786c57a commit f281ce5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ nixpkgs_package(
repository = "@nixpkgs",
)

# This bazel build @output-derivation-is-a-file//... must fail
# See https://github.com/tweag/rules_nixpkgs/issues/99 for details
nixpkgs_package(
name = "output-derivation-is-a-file",
attribute_path = "",
nix_file_content = """let pkgs = import <nixpkgs> { config = {}; overlays = []; }; in pkgs.writeText "foo" "bar" """,
nix_file_deps = [
"//:nixpkgs.json",
"//:nixpkgs.nix",
"//tests:relative_imports/nixpkgs.nix",
],
repository = "@nixpkgs",
)

nixpkgs_cc_configure(repository = "@remote_nixpkgs")

nixpkgs_python_configure(repository = "@remote_nixpkgs")
Expand Down
8 changes: 8 additions & 0 deletions nixpkgs/nixpkgs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ def _nixpkgs_package_impl(repository_ctx):
)
output_path = exec_result.stdout.splitlines()[-1]

# ensure that the output is a directory
test_path = repository_ctx.which("test")
_execute_or_fail(repository_ctx, [test_path, "-d", output_path],
failure_message = "nixpkgs_package '@{}' outputs a single file which is not supported by rule_nixpkgs. Please only use directory.".format(
repository_ctx.name
),
)

# Build a forest of symlinks (like new_local_package() does) to the
# Nix store.
for target in _find_children(repository_ctx, output_path):
Expand Down

0 comments on commit f281ce5

Please sign in to comment.