-
Notifications
You must be signed in to change notification settings - Fork 84
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
Allow passing several labels to nixpkgs_package
#29
Conversation
Mh I've absolutely no idea what the CI failure means and it doesn't seem related to my work… |
Looks like an upstream regression: bazelbuild/bazel#5946. We're hit by this because we're not currently pinning a nixpkgs version in this repository. |
nixpkgs/nixpkgs.bzl
Outdated
**kwargs | ||
) | ||
|
||
def nix_instantiate(*args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this function used anywhere? It looks like dead code to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch sorry, pushed the wrong commit :/
Should be fixed now
nixpkgs/nixpkgs.bzl
Outdated
"repository": attr.label(), | ||
"build_file": attr.label(), | ||
"build_file_content": attr.string(), | ||
}, | ||
local = True, | ||
) | ||
|
||
def nixpkgs_package(*args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for changing this rule to a macro that calls a single rule?
17818ef
to
cdcc316
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you say more about your use case? The extra generality sounds good to me, but current limitations of Bazel are forcing us to adopt an unfortunate API. While the API works, it's semantically dubious and it's an API we'll have to keep that way forever in the future unless we accept making a breaking change in the future. So ideally, if you can make do with a workaround while we work with upstream to get the feature we want in Bazel, we would delay applying this patch until upstream is fixed.
See bazelbuild/bazel#5356 for the upstream ticket. |
It's motivated by tweag/rules_haskell#442 where I need |
Would an approach such as bazelbuild/bazel#5356 be OK for you if we wrap the rule inside a macro which takes as argument a |
That's a good idea. Provided it solves the forward compatibility problem. That's the main constraint. |
I think the idea behind the change is sensible, for other uses, but in this case you don’t necessarily need to add your file to
to
|
@Profpatsch that's true (and being able to pass arguments to the nix expression would be cool), but the |
I just stumbled upon another use-case for this: We have a master project using Afaik there is no easy way to do this at the moment, while with this change it can be done by adding |
@@ -94,7 +104,7 @@ def _nixpkgs_package_impl(ctx): | |||
timeout = 1073741824 | |||
|
|||
res = ctx.execute(nix_build, quiet = False, timeout = timeout, | |||
environment=dict(NIX_PATH="nixpkgs=" + nix_path)) | |||
environment=dict(NIX_PATH=nix_path)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks the path
argument, since it’s not of the form "nixpkgs=path"
anymore.
I’d rename |
Deprecates the `repository` attribute in favor of the more general `repositories` which expects a dict of the form ```python { "@some_label": "some_name", "@some_other_label": "some_other_name", } ``` and generating the `NIX_PATH` `some_name=path(@some_label):some_other_name=path(@some_other_label)`
Make the `repositories` argument of the form `{ path_element_name: label }` instead of `{ label: path_element_name }`
b81967b
to
2a05982
Compare
Rebased the changes. |
This was a holdover from a previous version of #29.
Before #29, we'd write ```python nixpkgs_package(name = "hello", repository = "@nixpkgs") ``` and this would just work. Now we write ```python nixpkgs_package(name = "hello", repositories = { "nixpkgs": "@nixpkgs//:default.nix" }) ``` which is quite a bit more verbose. With this fix, writing the repository label as `"@nixpkgs"` works again. Fixes #41.
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.
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.
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.
Before #29, we'd write ```python nixpkgs_package(name = "hello", repository = "@nixpkgs") ``` and this would just work. Now we write ```python nixpkgs_package(name = "hello", repositories = { "nixpkgs": "@nixpkgs//:default.nix" }) ``` which is quite a bit more verbose. With this fix, writing the repository label as `"@nixpkgs"` works again. Fixes #41.
Deprecates the
repository
attribute in favor of the more generalrepositories
which expects a dict of the formand generating the
NIX_PATH
some_name=path(@some_label):some_other_name=path(@some_other_label)
I also have a couple of questions regarding this:
{ "name": "@label"}
instead of{ "@labelb: "name"}
, but the docs at https://docs.bazel.build/versions/master/skylark/lib/attr.html only mentionslabel_keyed_string_dict
and not something likestring_keyed_label_dict
. Does anyone knows whether there is a way to build custom types for attrs?README
. Is it the right way to do so or is it generated in some way?