From 2a0598278e897958b1246148443c800cc4e2a034 Mon Sep 17 00:00:00 2001 From: regnat Date: Thu, 20 Sep 2018 00:47:32 +0200 Subject: [PATCH] Give a nicer interface to `nixpkgs_package` Make the `repositories` argument of the form `{ path_element_name: label }` instead of `{ label: path_element_name }` --- WORKSPACE | 12 ++++++------ nixpkgs/nixpkgs.bzl | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 6d74e7434..a35b5ddc0 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -4,37 +4,37 @@ load("//nixpkgs:nixpkgs.bzl", "nixpkgs_git_repository", "nixpkgs_package") # For tests -nixpkgs_package(name = "hello", repositories = { "//:nix/default.nix": "nixpkgs" }) +nixpkgs_package(name = "hello", repositories = { "nixpkgs": "//:nix/default.nix" }) nixpkgs_package( name = "expr-test", nix_file_content = "let pkgs = import {}; in pkgs.hello", - repositories = { "//:nix/default.nix": "nixpkgs" } + repositories = { "nixpkgs": "//:nix/default.nix" } ) nixpkgs_package( name = "attribute-test", attribute_path = "hello", - repositories = { "//:nix/default.nix": "nixpkgs" } + repositories = { "nixpkgs": "//:nix/default.nix" } ) nixpkgs_package( name = "expr-attribute-test", nix_file_content = "import {}", attribute_path = "hello", - repositories = { "//:nix/default.nix": "nixpkgs" }, + repositories = { "nixpkgs": "//:nix/default.nix" }, ) nixpkgs_package( name = "nix-file-test", nix_file = "//tests:nixpkgs.nix", attribute_path = "hello", - repositories = { "//:nix/default.nix": "nixpkgs" }, + repositories = { "nixpkgs": "//:nix/default.nix" }, ) nixpkgs_package( name = "nix-file-deps-test", nix_file = "//tests:hello.nix", nix_file_deps = ["//tests:pkgname.nix"], - repositories = { "//:nix/default.nix": "nixpkgs" }, + repositories = { "nixpkgs": "//:nix/default.nix" }, ) diff --git a/nixpkgs/nixpkgs.bzl b/nixpkgs/nixpkgs.bzl index 67c2f16ae..90f02f36f 100644 --- a/nixpkgs/nixpkgs.bzl +++ b/nixpkgs/nixpkgs.bzl @@ -116,7 +116,7 @@ def _nixpkgs_package_impl(ctx): _symlink_children(output_path, ctx) -nixpkgs_package = repository_rule( +_nixpkgs_package = repository_rule( implementation = _nixpkgs_package_impl, attrs = { "attribute_path": attr.string(), @@ -132,6 +132,19 @@ nixpkgs_package = repository_rule( local = True, ) +def nixpkgs_package(repositories, *args, **kwargs): + # Because of https://github.com/bazelbuild/bazel/issues/5356 we can't + # directly pass a dict from strings to labels to the rule (which we'd like + # 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). + inversed_repositories = { value: key for (key, value) in repositories.items() } + _nixpkgs_package( + repositories = inversed_repositories, + *args, + **kwargs + ) + def _symlink_children(target_dir, rep_ctx): """Create a symlink to all children of `target_dir` in the current build directory."""