Skip to content

Commit 7e455ad

Browse files
authored
Merge pull request #18 from tweag/gb/cache_nixpkgs_package
Introduce a `data` attribute to `nixpkgs_package`
2 parents 26dcf41 + f028a8b commit 7e455ad

File tree

6 files changed

+32
-2
lines changed

6 files changed

+32
-2
lines changed

README.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ nixpkgs_git_repository(name, revision)
8181
Make the content of a Nixpkgs package available in the Bazel workspace.
8282

8383
```bzl
84-
nixpkgs_package(name, attribute_path, nix_file, nix_file_content,
85-
path, repository, build_file, build_file_content)
84+
nixpkgs_package(
85+
name, attribute_path, nix_file, nix_file_deps, nix_file_content,
86+
path, repository, build_file, build_file_content,
87+
)
8688
```
8789

8890
If neither `repository` or `path` are specified, `<nixpkgs>` is
@@ -123,6 +125,13 @@ recommended. The two are mutually exclusive.
123125
<p>A file containing an expression for a Nix derivation.</p>
124126
</td>
125127
</tr>
128+
<tr>
129+
<td><code>nix_file_deps</code></td>
130+
<td>
131+
<p><code>List of labels; optional</code></p>
132+
<p>Dependencies of `nix_file` if any.</p>
133+
</td>
134+
</tr>
126135
<tr>
127136
<td><code>nix_file_content</code></td>
128137
<td>

WORKSPACE

+8
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,11 @@ nixpkgs_package(
3636
attribute_path = "hello",
3737
repository = "@nixpkgs",
3838
)
39+
40+
nixpkgs_package(
41+
name = "nix-file-deps-test",
42+
nix_file = "//tests:hello.nix",
43+
nix_file_deps = ["//tests:pkgname.nix"],
44+
repository = "@nixpkgs",
45+
)
46+

nixpkgs/nixpkgs.bzl

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ def _nixpkgs_package_impl(ctx):
3737
else:
3838
expr_args = ["-E", "import <nixpkgs> {}"]
3939

40+
# Introduce an artificial dependency with a bogus name on each of
41+
# the nix_file_deps.
42+
for dep in ctx.attr.nix_file_deps:
43+
components = [c for c in [dep.workspace_root, dep.package, dep.name] if c]
44+
link = '/'.join(components).replace('_', '_U').replace('/', '_S')
45+
ctx.symlink(dep, link)
46+
4047
expr_args.extend([
4148
"-A", ctx.attr.attribute_path
4249
if ctx.attr.nix_file or ctx.attr.nix_file_content
@@ -98,6 +105,7 @@ nixpkgs_package = repository_rule(
98105
attrs = {
99106
"attribute_path": attr.string(),
100107
"nix_file": attr.label(allow_single_file = [".nix"]),
108+
"nix_file_deps": attr.label_list(),
101109
"nix_file_content": attr.string(),
102110
"path": attr.string(),
103111
"repository": attr.label(),

tests/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ package(default_testonly = 1)
1212
"attribute-test",
1313
"expr-attribute-test",
1414
"nix-file-test",
15+
"nix-file-deps-test",
1516
]]

tests/hello.nix

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
with import ./pkgname.nix;
2+
let pkgs = import <nixpkgs> {}; in builtins.getAttr pkgname pkgs
3+

tests/pkgname.nix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ pkgname = "hello"; }

0 commit comments

Comments
 (0)