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. |
Create an external repository representing the content of Nixpkgs,
based on a Nix expression stored locally or provided inline. One of
nix_file
or nix_file_content
must be provided.
nixpkgs_local_repository(name, nix_file, nix_file_deps, nix_file_content)
Attributes | |
---|---|
name |
A unique name for this repository. |
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. |
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,
repository, 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 |
A repository label identifying which Nixpkgs to use. Equivalent to `repositories = { "nixpkgs": ...}` |
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 |
Tells Bazel to use compilers and linkers from Nixpkgs for the CC
toolchain. By default, Bazel autodetects a toolchain on the current
PATH
. Overriding this autodetection makes builds more hermetic and
is considered a best practice.
Example:
nixpkgs_cc_configure(repository = "@nixpkgs//:default.nix")
Attributes | |
---|---|
nix_file |
An expression for a Nix environment derivation. The environment should expose all the commands that make up a CC toolchain (`cc`, `ld` etc). Exposes all commands in `stdenv.cc` and `binutils` by default. |
nix_file_deps |
Dependencies of `nix_file` if any. |
nix_file_content |
An expression for a Nix environment derivation. |
repository |
A repository label identifying which Nixpkgs to use. Equivalent to `repositories = { "nixpkgs": ...}` |
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`. |
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",
},
…
)