From f281ce524141fd6a57ea7fe32f1537e75a0171f3 Mon Sep 17 00:00:00 2001 From: Guillaume Bouchard Date: Mon, 2 Dec 2019 19:14:26 +0100 Subject: [PATCH] Fail when nixpkgs_package output is a single file This closes #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. --- WORKSPACE | 14 ++++++++++++++ nixpkgs/nixpkgs.bzl | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/WORKSPACE b/WORKSPACE index 61b441cc1..ae756ff13 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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 { 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") diff --git a/nixpkgs/nixpkgs.bzl b/nixpkgs/nixpkgs.bzl index 92d9fe7c9..c78bc5672 100644 --- a/nixpkgs/nixpkgs.bzl +++ b/nixpkgs/nixpkgs.bzl @@ -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):