Skip to content

Commit

Permalink
Give a nicer interface to nixpkgs_package
Browse files Browse the repository at this point in the history
Make the `repositories` argument of the form `{ path_element_name: label
}` instead of `{ label: path_element_name }`
  • Loading branch information
thufschmitt authored and Profpatsch committed Oct 16, 2018
1 parent 485826e commit 2a05982
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
12 changes: 6 additions & 6 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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 <nixpkgs> {}; 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 <nixpkgs> {}",
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" },
)
15 changes: 14 additions & 1 deletion nixpkgs/nixpkgs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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."""
Expand Down

0 comments on commit 2a05982

Please sign in to comment.