From af33159573d484edf5d58cfba19126bb6df9a6e6 Mon Sep 17 00:00:00 2001 From: Mathieu Boespflug Date: Tue, 13 Nov 2018 22:05:41 +0100 Subject: [PATCH] Undeprecate the repository attribute PR #29 introduced the `repositories` attribute. But specifying a single repository is a common enough use case that we should continue to support it as before, without extra verbosity. --- README.md | 8 +++++--- nixpkgs/nixpkgs.bzl | 21 ++++++++------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4f72dd1a2..77d622433 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ Make the content of a Nixpkgs package available in the Bazel workspace. ```bzl nixpkgs_package( name, attribute_path, nix_file, nix_file_deps, nix_file_content, - repositories, build_file, build_file_content, + repository, repositories, build_file, build_file_content, ) ``` @@ -160,7 +160,8 @@ nixpkgs clone in `nix_file` or `nix_file_content`. repository

Label; optional

-

Deprecated, use `repositories` instead.

+

A repository label identifying which Nixpkgs to use. + Equivalent to `repositories = { "nixpkgs": ...}`

@@ -261,7 +262,8 @@ nixpkgs_cc_configure(repository = "@nixpkgs//:default.nix") repository

Label; optional

-

A repository label identifying which Nixpkgs to use.

+

A repository label identifying which Nixpkgs to use. + Equivalent to `repositories = { "nixpkgs": ...}`

diff --git a/nixpkgs/nixpkgs.bzl b/nixpkgs/nixpkgs.bzl index 06c5c93a7..78f6b6ba8 100644 --- a/nixpkgs/nixpkgs.bzl +++ b/nixpkgs/nixpkgs.bzl @@ -23,14 +23,13 @@ nixpkgs_git_repository = repository_rule( ) def _nixpkgs_package_impl(repository_ctx): - repositories = None - if repository_ctx.attr.repositories: - repositories = repository_ctx.attr.repositories + repository = repository_ctx.attr.repository + repositories = repository_ctx.attr.repositories - if repository_ctx.attr.repository: - print("The 'repository' attribute is deprecated, use 'repositories' instead") - repositories = { repository_ctx.attr.repository: "nixpkgs" } + \ - (repositories if repositories else {}) + if repository and repositories or not repository and not repositories: + fail("Specify one of 'repository' or 'repositories' (but not both).") + elif repository: + repositories = { repository_ctx.attr.repository: "nixpkgs" } if repository_ctx.attr.build_file and repository_ctx.attr.build_file_content: fail("Specify one of 'build_file' or 'build_file_content', but not both.") @@ -139,7 +138,7 @@ def nixpkgs_package(*args, **kwargs): # for the `repositories` arguments), but we can pass a dict from labels to # strings. So we swap the keys and the values (assuming they all are # distinct). - if "repositories" in kwargs: + if "repositories" in kwargs and kwargs["repositories"]: inversed_repositories = { value: key for (key, value) in kwargs["repositories"].items() } kwargs.pop("repositories") _nixpkgs_package( @@ -196,13 +195,9 @@ def nixpkgs_cc_configure( this rule to specific explicitly which commands the toolchain should use. """ - if repository and repositories or not repository and not repositories: - fail("Specify one of repository or repositories (but not both).") - elif repository: - repositories = {"nixpkgs": repository} - nixpkgs_package( name = "nixpkgs_cc_toolchain", + repository = repository, repositories = repositories, nix_file_content = nix_file_content, build_file_content = """exports_files(glob(["bin/*"]))""",