Rules for importing Nixpkgs packages into Bazel.
Add the following to your WORKSPACE
file, and select a $COMMIT
accordingly.
http_archive(
name = "io_tweag_rules_nixpkgs",
strip_prefix = "rules_nixpkgs-$COMMIT",
urls = ["https://github.com/tweag/rules_nixpkgs/archive/$COMMIT.tar.gz"],
)
load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_git_repository", "nixpkgs_package")
nixpkgs_git_repository(
name = "nixpkgs",
revision = "17.09", # Any tag or commit hash
sha256 = "" # optional sha to verify package integrity!
)
nixpkgs_package(
name = "hello",
repositories = { "nixpkgs": "@nixpkgs//:default.nix" }
)
Name a specific revision of Nixpkgs on GitHub or a local checkout.
nixpkgs_git_repository(name, revision, sha256)
Attributes | |
---|---|
name |
A unique name for this repository. |
revision |
Git commit hash or tag identifying the version of Nixpkgs to use. |
remote |
The URI of the remote Git repository. This must be a HTTP URL. There is currently no support for authentication. Defaults to upstream nixpkgs. |
sha256 |
The SHA256 used to verify the integrity of the repository. |
Make the content of a Nixpkgs package available in the Bazel workspace.
nixpkgs_package(
name, attribute_path, nix_file, nix_file_deps, nix_file_content,
repositories, build_file, build_file_content,
)
If repositories
is not specified, you must provide a
nixpkgs clone in nix_file
or nix_file_content
.
Attributes | |
---|---|
name |
A unique name for this target |
attribute_path |
Select an attribute from the top-level Nix expression being evaluated. The attribute path is a sequence of attribute names separated by dots. |
nix_file |
A file containing an expression for a Nix derivation. |
nix_file_deps |
Dependencies of `nix_file` if any. |
nix_file_content |
An expression for a Nix derivation. |
repository |
Deprecated, use `repositories` instead. |
repositories |
A dictionary mapping `NIX_PATH` entries to repository labels. Setting it to
<myrepo> in the called nix code by the
path to the target "//:myrepo" . See the
relevant
section in the nix manual for more information.
Specify one of `path` or `repositories`. |
build_file |
The file to use as the BUILD file for this repository.
Its contents are copied copied into the file
For common use cases we provide filegroups that expose certain files as targets:
If you need different files from the nix package, you can reference them like this:
|
build_file_content |
Like |
path
was an attribute from the early days of rules_nixpkgs
, and
its ability to reference arbitrary paths a danger to build hermeticity.
Replace it with either nixpkgs_git_repository
if you need
a specific version of nixpkgs
. If you absolutely must depend on a
local folder, use bazel’s
local_repository
workspace rule.
Both approaches work well with the repositories
attribute of nixpkgs_package
.
local_repository(
name = "local-nixpkgs",
path = "/path/to/nixpkgs",
)
nixpkgs_package(
name = "somepackage",
repositories = {
"nixpkgs": "@local-nixpkgs//:default.nix",
},
…
)