diff --git a/WORKSPACE b/WORKSPACE index c6a78772..61b441cc 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -7,6 +7,7 @@ load( "nixpkgs_local_repository", "nixpkgs_package", "nixpkgs_python_configure", + "nixpkgs_sh_posix_configure", ) # For tests @@ -118,3 +119,22 @@ nixpkgs_package( nixpkgs_cc_configure(repository = "@remote_nixpkgs") nixpkgs_python_configure(repository = "@remote_nixpkgs") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "rules_sh", + sha256 = "2613156e96b41fe0f91ac86a65edaea7da910b7130f2392ca02e8270f674a734", + strip_prefix = "rules_sh-0.1.0", + urls = ["https://github.com/tweag/rules_sh/archive/v0.1.0.tar.gz"], +) + +load("@rules_sh//sh:repositories.bzl", "rules_sh_dependencies") + +rules_sh_dependencies() + +nixpkgs_sh_posix_configure(repository = "@nixpkgs") + +load("@rules_sh//sh:posix.bzl", "sh_posix_configure") + +sh_posix_configure() diff --git a/nixpkgs/nixpkgs.bzl b/nixpkgs/nixpkgs.bzl index 1d54c6bd..92d9fe7c 100644 --- a/nixpkgs/nixpkgs.bzl +++ b/nixpkgs/nixpkgs.bzl @@ -431,6 +431,130 @@ def nixpkgs_python_configure( ) native.register_toolchains("@%s//:toolchain" % name) +def nixpkgs_sh_posix_config(name, packages, **kwargs): + nixpkgs_package( + name = name, + nix_file_content = """ +with import {{ config = {{}}; overlays = []; }}; + +let + # `packages` might include lists, e.g. `stdenv.initialPath` is a list itself, + # so we need to flatten `packages`. + flatten = builtins.concatMap (x: if builtins.isList x then x else [x]); + env = buildEnv {{ + name = "posix-toolchain"; + paths = flatten [ {} ]; + }}; + cmd_glob = "${{env}}/bin/*"; + os = if stdenv.isDarwin then "osx" else "linux"; +in + +runCommand "bazel-nixpkgs-posix-toolchain" + {{ executable = false; + # Pointless to do this on a remote machine. + preferLocalBuild = true; + allowSubstitutes = false; + }} + '' + n=$out/nixpkgs_sh_posix.bzl + mkdir -p "$(dirname "$n")" + + cat >>$n <>$n + fi + done + cat >>$n <&2 + fail=1 + fi +done +exit $fail