# rules_nixpkgs [![CircleCI](https://circleci.com/gh/tweag/rules_nixpkgs.svg?style=svg)](https://circleci.com/gh/tweag/rules_nixpkgs) Rules for importing Nixpkgs packages into Bazel. ## Rules * [nixpkgs_git_repository](#nixpkgs_git_repository) * [nixpkgs_package](#nixpkgs_package) ## Setup Add the following to your `WORKSPACE` file, and select a `$COMMIT` accordingly. ```bzl 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") ``` ## Example ```bzl 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" } ) ``` ## Rules ### nixpkgs_git_repository Name a specific revision of Nixpkgs on GitHub or a local checkout. ```bzl 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. |
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. |
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
for example would replace all instances
of <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:
See the bazel documentation of
filegroup
and
glob.
|
build_file_content |
Like |
nixopts |
Extra flags to pass when calling Nix. |
fail_not_supported |
If set to |
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
for example would replace all instances
of <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`. |