Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a data attribute to nixpkgs_package #18

Merged
merged 3 commits into from
Jun 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ nixpkgs_git_repository(name, revision)
Make the content of a Nixpkgs package available in the Bazel workspace.

```bzl
nixpkgs_package(name, attribute_path, nix_file, nix_file_content,
path, repository, build_file, build_file_content)
nixpkgs_package(
name, attribute_path, nix_file, nix_file_deps, nix_file_content,
path, repository, build_file, build_file_content,
)
```

If neither `repository` or `path` are specified, `<nixpkgs>` is
Expand Down Expand Up @@ -123,6 +125,13 @@ recommended. The two are mutually exclusive.
<p>A file containing an expression for a Nix derivation.</p>
</td>
</tr>
<tr>
<td><code>nix_file_deps</code></td>
<td>
<p><code>List of labels; optional</code></p>
<p>Dependencies of `nix_file` if any.</p>
</td>
</tr>
<tr>
<td><code>nix_file_content</code></td>
<td>
Expand Down
8 changes: 8 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ nixpkgs_package(
attribute_path = "hello",
repository = "@nixpkgs",
)

nixpkgs_package(
name = "nix-file-deps-test",
nix_file = "//tests:hello.nix",
nix_file_deps = ["//tests:pkgname.nix"],
repository = "@nixpkgs",
)

8 changes: 8 additions & 0 deletions nixpkgs/nixpkgs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ def _nixpkgs_package_impl(ctx):
else:
expr_args = ["-E", "import <nixpkgs> {}"]

# Introduce an artificial dependency with a bogus name on each of
# the nix_file_deps.
for dep in ctx.attr.nix_file_deps:
components = [c for c in [dep.workspace_root, dep.package, dep.name] if c]
link = '/'.join(components).replace('_', '_U').replace('/', '_S')
ctx.symlink(dep, link)

expr_args.extend([
"-A", ctx.attr.attribute_path
if ctx.attr.nix_file or ctx.attr.nix_file_content
Expand Down Expand Up @@ -98,6 +105,7 @@ nixpkgs_package = repository_rule(
attrs = {
"attribute_path": attr.string(),
"nix_file": attr.label(allow_single_file = [".nix"]),
"nix_file_deps": attr.label_list(),
"nix_file_content": attr.string(),
"path": attr.string(),
"repository": attr.label(),
Expand Down
1 change: 1 addition & 0 deletions tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ package(default_testonly = 1)
"attribute-test",
"expr-attribute-test",
"nix-file-test",
"nix-file-deps-test",
]]
3 changes: 3 additions & 0 deletions tests/hello.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
with import ./pkgname.nix;
let pkgs = import <nixpkgs> {}; in builtins.getAttr pkgname pkgs

1 change: 1 addition & 0 deletions tests/pkgname.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ pkgname = "hello"; }