From 8cd16d916bbb8abf91678d160da2587a56a010da Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Tue, 15 Jan 2019 14:42:42 +0100 Subject: [PATCH 1/3] Allow no-op rules on Windows --- nixpkgs/nixpkgs.bzl | 67 +++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/nixpkgs/nixpkgs.bzl b/nixpkgs/nixpkgs.bzl index 72df34dc2..bb47d8344 100644 --- a/nixpkgs/nixpkgs.bzl +++ b/nixpkgs/nixpkgs.bzl @@ -60,6 +60,11 @@ def _nixpkgs_package_impl(repository_ctx): repository = repository_ctx.attr.repository repositories = repository_ctx.attr.repositories + # Is nix supported on this platform? + not_supported = repository_ctx.os.name.startswith("windows") + # Should we fail if Nix is not supported? + fail_not_supported = repository_ctx.attr.fail_not_supported + if repository and repositories or not repository and not repositories: fail("Specify one of 'repository' or 'repositories' (but not both).") elif repository: @@ -121,35 +126,40 @@ def _nixpkgs_package_impl(repository_ctx): elif not (repository_ctx.attr.nix_file or repository_ctx.attr.nix_file_content): fail(strFailureImplicitNixpkgs) - nix_build_path = _executable_path( - repository_ctx, - "nix-build", - extra_msg = "See: https://nixos.org/nix/", - ) - nix_build = [nix_build_path] + expr_args - # Large enough integer that Bazel can still parse. We don't have - # access to MAX_INT and 0 is not a valid timeout so this is as good - # as we can do. - timeout = 1073741824 - - exec_result = _execute_or_fail( - repository_ctx, - nix_build, - failure_message = "Cannot build Nix attribute '{}'.".format( - repository_ctx.attr.attribute_path, - ), - quiet = False, - timeout = timeout, - environment = dict(NIX_PATH = nix_path), - ) - output_path = exec_result.stdout.splitlines()[-1] + if not_supported and fail_not_supported: + fail("Platform is not supported (see 'fail_not_supported')") + elif not_supported: + return + else: + nix_build_path = _executable_path( + repository_ctx, + "nix-build", + extra_msg = "See: https://nixos.org/nix/", + ) + nix_build = [nix_build_path] + expr_args + + # Large enough integer that Bazel can still parse. We don't have + # access to MAX_INT and 0 is not a valid timeout so this is as good + # as we can do. + timeout = 1073741824 + exec_result = _execute_or_fail( + repository_ctx, + nix_build, + failure_message = "Cannot build Nix attribute '{}'.".format( + repository_ctx.attr.attribute_path, + ), + quiet = False, + timeout = timeout, + environment = dict(NIX_PATH = nix_path), + ) + output_path = exec_result.stdout.splitlines()[-1] - # Build a forest of symlinks (like new_local_package() does) to the - # Nix store. - for target in _find_children(repository_ctx, output_path): - basename = target.rpartition("/")[-1] - repository_ctx.symlink(target, basename) + # Build a forest of symlinks (like new_local_package() does) to the + # Nix store. + for target in _find_children(repository_ctx, output_path): + basename = target.rpartition("/")[-1] + repository_ctx.symlink(target, basename) _nixpkgs_package = repository_rule( implementation = _nixpkgs_package_impl, @@ -163,6 +173,9 @@ _nixpkgs_package = repository_rule( "build_file": attr.label(), "build_file_content": attr.string(), "nixopts": attr.string_list(), + "fail_not_supported": attr.bool(default = True, doc = """ + If set to True (default) this rule will failed on platforms which do not support Nix (e.g. Windows). If set to False calling this rule will succeed but no output will be generated. + """), }, ) From 88f2445d6040e26e5d4cd028141bb30b5efb635e Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Tue, 15 Jan 2019 16:35:37 +0100 Subject: [PATCH 2/3] Document fail_not_supported --- README.md | 13 +++++++++++++ nixpkgs/nixpkgs.bzl | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ff250db9..c4d8403a5 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,7 @@ 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, + fail_not_supported, ) ``` @@ -276,6 +277,18 @@ filegroup( instead of a file name.

+ + fail_not_supported + +

Boolean; optional; default = True

+

+ If set to True (default) this rule will fail on + platforms which do not support Nix (e.g. Windows). If set to + False calling this rule will succeed but no output + will be generated. +

+ + diff --git a/nixpkgs/nixpkgs.bzl b/nixpkgs/nixpkgs.bzl index bb47d8344..72aeeb771 100644 --- a/nixpkgs/nixpkgs.bzl +++ b/nixpkgs/nixpkgs.bzl @@ -174,7 +174,7 @@ _nixpkgs_package = repository_rule( "build_file_content": attr.string(), "nixopts": attr.string_list(), "fail_not_supported": attr.bool(default = True, doc = """ - If set to True (default) this rule will failed on platforms which do not support Nix (e.g. Windows). If set to False calling this rule will succeed but no output will be generated. + If set to True (default) this rule will fail on platforms which do not support Nix (e.g. Windows). If set to False calling this rule will succeed but no output will be generated. """), }, ) From b187de9f1264e455a522f172b1e99078a38d19eb Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Wed, 16 Jan 2019 16:14:59 +0100 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 555b7b5c4..af3a1aed9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/). +## [Unreleased] +### Added +- `nixpkgs_package` now has a new optional argument `fail_not_supported` + allowing the rule to _not_ fail on Windows (when set to `False`) + ## [0.5.1] - 2018-12-18 ### Changed