Skip to content

Commit

Permalink
Merge pull request tweag#106 from tweag/no_default_BUILD
Browse files Browse the repository at this point in the history
Only create BUILD file if needed
  • Loading branch information
mboes authored Feb 21, 2020
2 parents 531804b + 6bcc74e commit c966bb8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion nixpkgs/nixpkgs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,19 @@ def _nixpkgs_package_impl(repository_ctx):
elif repository:
repositories = {repository_ctx.attr.repository: "nixpkgs"}

# If true, a BUILD file will be created from a template if it does not
# exits.
# However this will happen AFTER the nix-build command.
create_build_file_if_needed = False
if repository_ctx.attr.build_file and repository_ctx.attr.build_file_content:
fail("Specify one of 'build_file' or 'build_file_content', but not both.")
elif repository_ctx.attr.build_file:
repository_ctx.symlink(repository_ctx.attr.build_file, "BUILD")
elif repository_ctx.attr.build_file_content:
repository_ctx.file("BUILD", content = repository_ctx.attr.build_file_content)
else:
repository_ctx.template("BUILD", Label("@io_tweag_rules_nixpkgs//nixpkgs:BUILD.pkg"))
# No user supplied build file, we may create the default one.
create_build_file_if_needed = True

strFailureImplicitNixpkgs = (
"One of 'repositories', 'nix_file' or 'nix_file_content' must be provided. " +
Expand Down Expand Up @@ -176,6 +181,13 @@ def _nixpkgs_package_impl(repository_ctx):
basename = target.rpartition("/")[-1]
repository_ctx.symlink(target, basename)

# Create a default BUILD file only if it does not exists and is not
# provided by `build_file` or `build_file_content`.
if create_build_file_if_needed:
p = repository_ctx.path("BUILD")
if not p.exists:
repository_ctx.template("BUILD", Label("@io_tweag_rules_nixpkgs//nixpkgs:BUILD.pkg"))

_nixpkgs_package = repository_rule(
implementation = _nixpkgs_package_impl,
attrs = {
Expand Down

0 comments on commit c966bb8

Please sign in to comment.