{"action":"created","comment":{"url":"https://api.github.com/repos/tweag/rules_nixpkgs/pulls/comments/232728030","pull_request_review_id":173936458,"id":232728030,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzMjcyODAzMA==","diff_hunk":"@@ -185,3 +186,63 @@ stderr:\n   code=exec_result.return_code,\n   stdout=exec_result.stdout,\n   stderr=exec_result.stderr))\n+\n+def _nixpkgs_cc_autoconf_impl(repository_ctx):\n+  # Calling repository_ctx.path() on anything but a regular file\n+  # fails. So the roundabout way to do the same thing is to find\n+  # a regular file we know is in the workspace (i.e. the WORKSPACE\n+  # file itself) and then use dirname to get the path of the workspace\n+  # root.\n+  workspace_file_path = repository_ctx.path(\n+    Label(\"@nixpkgs_cc_toolchain//:WORKSPACE\")\n+  )\n+  workspace_root = repository_ctx.execute(\n+    [\"dirname\", workspace_file_path]\n+  ).stdout.rstrip()\n+\n+  # Make a list of all available tools in the Nix derivation. Override\n+  # the Bazel autoconfiguration with the tools we found.\n+  res = repository_ctx.execute([\"ls\", workspace_root + \"/bin\"])\n+  if res.return_code == 0:\n+    overriden_tools = {\n+      tool: repository_ctx.path(Label(\"@nixpkgs_cc_toolchain//:bin/\" + tool))\n+      for tool in res.stdout.splitlines()\n+    }\n+    cc_autoconf_impl(repository_ctx, overriden_tools = overriden_tools)\n+  else:\n+    fail(\"Cannot list content of @nixpkgs_cc_toolchain:\" + res.stderr)\n+\n+_nixpkgs_cc_autoconf = repository_rule(\n+  implementation = _nixpkgs_cc_autoconf_impl\n+)\n+\n+def nixpkgs_cc_configure(\n+    repository = None,\n+    repositories = None,\n+    nix_file_content = \"\"\"\n+      with import <nixpkgs> {}; buildEnv {\n+        name = \"bazel-cc-toolchain\";\n+        paths = [ gcc binutils ];\n+      }\n+    \"\"\"):\n+  \"\"\"Use a CC toolchain from Nixpkgs.\n+  \n+  By default, Bazel auto-configures a CC toolchain from commands (e.g.\n+  `gcc`) available in the environment. To make builds more hermetic, use\n+  this rule to specific explicitly which commands the toolchain should\n+  use.\n+  \"\"\"\n+  if repository and repositories or not repository and not repositories:\n+    fail(\"Specify one of repository or repositories (but not both).\")\n+  elif repository:\n+    repositories = {\"nixpkgs\": repository}\n+\n+  nixpkgs_package(\n+    name = \"nixpkgs_cc_toolchain\",\n+    repositories = repositories,\n+    nix_file_content = nix_file_content,\n+    build_file_content = \"\"\"exports_files(glob([\"bin/*\"]))\"\"\",\n+  )\n+  _nixpkgs_cc_autoconf(name = \"local_config_cc\")\n+  native.bind(name = \"cc_toolchain\", actual = \"@local_config_cc//:toolchain\")","path":"nixpkgs/nixpkgs.bzl","position":76,"original_position":76,"commit_id":"2582aa24d2e6d374c206fc40df968b95dc971fc1","original_commit_id":"2582aa24d2e6d374c206fc40df968b95dc971fc1","user":{"login":"Profpatsch","id":3153638,"node_id":"MDQ6VXNlcjMxNTM2Mzg=","avatar_url":"https://avatars1.githubusercontent.com/u/3153638?v=4","gravatar_id":"","url":"https://api.github.com/users/Profpatsch","html_url":"https://github.com/Profpatsch","followers_url":"https://api.github.com/users/Profpatsch/followers","following_url":"https://api.github.com/users/Profpatsch/following{/other_user}","gists_url":"https://api.github.com/users/Profpatsch/gists{/gist_id}","starred_url":"https://api.github.com/users/Profpatsch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Profpatsch/subscriptions","organizations_url":"https://api.github.com/users/Profpatsch/orgs","repos_url":"https://api.github.com/users/Profpatsch/repos","events_url":"https://api.github.com/users/Profpatsch/events{/privacy}","received_events_url":"https://api.github.com/users/Profpatsch/received_events","type":"User","site_admin":false},"body":"[Using `bind` is not recommended](https://docs.bazel.build/versions/master/be/workspace.html#bind). Afaik it’s not deprecated though.","created_at":"2018-11-12T16:34:55Z","updated_at":"2018-11-12T16:39:11Z","html_url":"https://github.com/tweag/rules_nixpkgs/pull/40#discussion_r232728030","pull_request_url":"https://api.github.com/repos/tweag/rules_nixpkgs/pulls/40","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/tweag/rules_nixpkgs/pulls/comments/232728030"},"html":{"href":"https://github.com/tweag/rules_nixpkgs/pull/40#discussion_r232728030"},"pull_request":{"href":"https://api.github.com/repos/tweag/rules_nixpkgs/pulls/40"}}},"pull_request":{"url":"https://api.github.com/repos/tweag/rules_nixpkgs/pulls/40","id":229921398,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI5OTIxMzk4","html_url":"https://github.com/tweag/rules_nixpkgs/pull/40","diff_url":"https://github.com/tweag/rules_nixpkgs/pull/40.diff","patch_url":"https://github.com/tweag/rules_nixpkgs/pull/40.patch","issue_url":"https://api.github.com/repos/tweag/rules_nixpkgs/issues/40","number":40,"state":"open","locked":false,"title":"Add nixpkgs_cc_configure()","user":{"login":"mboes","id":51356,"node_id":"MDQ6VXNlcjUxMzU2","avatar_url":"https://avatars1.githubusercontent.com/u/51356?v=4","gravatar_id":"","url":"https://api.github.com/users/mboes","html_url":"https://github.com/mboes","followers_url":"https://api.github.com/users/mboes/followers","following_url":"https://api.github.com/users/mboes/following{/other_user}","gists_url":"https://api.github.com/users/mboes/gists{/gist_id}","starred_url":"https://api.github.com/users/mboes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mboes/subscriptions","organizations_url":"https://api.github.com/users/mboes/orgs","repos_url":"https://api.github.com/users/mboes/repos","events_url":"https://api.github.com/users/mboes/events{/privacy}","received_events_url":"https://api.github.com/users/mboes/received_events","type":"User","site_admin":false},"body":"A call to this macro in your WORKSPACE file is a simple one-liner. It\ndeclares a nixpkgs_package with all the tools we need for a CC\ntoolchain, and then gets Bazel to use them. Making sure the Bazel uses\nthe C compiler from Nixpkgs rather than whatever it autodetects on the\nPATH improves build hermeticity, and side steps a whole host of issues\nwe've been facing on rules_haskell due to system GCC wanting to link\nagainst the system GLIBC while Nixpkgs GCC wants another one.","created_at":"2018-11-10T23:58:41Z","updated_at":"2018-11-12T16:39:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2bb8727c6390986ec19bb4354110cf0d7f63e427","assignee":null,"assignees":[],"requested_reviewers":[{"login":"regnat","id":7226587,"node_id":"MDQ6VXNlcjcyMjY1ODc=","avatar_url":"https://avatars2.githubusercontent.com/u/7226587?v=4","gravatar_id":"","url":"https://api.github.com/users/regnat","html_url":"https://github.com/regnat","followers_url":"https://api.github.com/users/regnat/followers","following_url":"https://api.github.com/users/regnat/following{/other_user}","gists_url":"https://api.github.com/users/regnat/gists{/gist_id}","starred_url":"https://api.github.com/users/regnat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/regnat/subscriptions","organizations_url":"https://api.github.com/users/regnat/orgs","repos_url":"https://api.github.com/users/regnat/repos","events_url":"https://api.github.com/users/regnat/events{/privacy}","received_events_url":"https://api.github.com/users/regnat/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/tweag/rules_nixpkgs/pulls/40/commits","review_comments_url":"https://api.github.com/repos/tweag/rules_nixpkgs/pulls/40/comments","review_comment_url":"https://api.github.com/repos/tweag/rules_nixpkgs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tweag/rules_nixpkgs/issues/40/comments","statuses_url":"https://api.github.com/repos/tweag/rules_nixpkgs/statuses/2582aa24d2e6d374c206fc40df968b95dc971fc1","head":{"label":"tweag:cc-configure-with-nix","ref":"cc-configure-with-nix","sha":"2582aa24d2e6d374c206fc40df968b95dc971fc1","user":{"login":"tweag","id":6057932,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYwNTc5MzI=","avatar_url":"https://avatars3.githubusercontent.com/u/6057932?v=4","gravatar_id":"","url":"https://api.github.com/users/tweag","html_url":"https://github.com/tweag","followers_url":"https://api.github.com/users/tweag/followers","following_url":"https://api.github.com/users/tweag/following{/other_user}","gists_url":"https://api.github.com/users/tweag/gists{/gist_id}","starred_url":"https://api.github.com/users/tweag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tweag/subscriptions","organizations_url":"https://api.github.com/users/tweag/orgs","repos_url":"https://api.github.com/users/tweag/repos","events_url":"https://api.github.com/users/tweag/events{/privacy}","received_events_url":"https://api.github.com/users/tweag/received_events","type":"Organization","site_admin":false},"repo":{"id":113735960,"node_id":"MDEwOlJlcG9zaXRvcnkxMTM3MzU5NjA=","name":"rules_nixpkgs","full_name":"tweag/rules_nixpkgs","private":false,"owner":{"login":"tweag","id":6057932,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYwNTc5MzI=","avatar_url":"https://avatars3.githubusercontent.com/u/6057932?v=4","gravatar_id":"","url":"https://api.github.com/users/tweag","html_url":"https://github.com/tweag","followers_url":"https://api.github.com/users/tweag/followers","following_url":"https://api.github.com/users/tweag/following{/other_user}","gists_url":"https://api.github.com/users/tweag/gists{/gist_id}","starred_url":"https://api.github.com/users/tweag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tweag/subscriptions","organizations_url":"https://api.github.com/users/tweag/orgs","repos_url":"https://api.github.com/users/tweag/repos","events_url":"https://api.github.com/users/tweag/events{/privacy}","received_events_url":"https://api.github.com/users/tweag/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/tweag/rules_nixpkgs","description":"Rules for importing Nixpkgs packages into Bazel.","fork":false,"url":"https://api.github.com/repos/tweag/rules_nixpkgs","forks_url":"https://api.github.com/repos/tweag/rules_nixpkgs/forks","keys_url":"https://api.github.com/repos/tweag/rules_nixpkgs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tweag/rules_nixpkgs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tweag/rules_nixpkgs/teams","hooks_url":"https://api.github.com/repos/tweag/rules_nixpkgs/hooks","issue_events_url":"https://api.github.com/repos/tweag/rules_nixpkgs/issues/events{/number}","events_url":"https://api.github.com/repos/tweag/rules_nixpkgs/events","assignees_url":"https://api.github.com/repos/tweag/rules_nixpkgs/assignees{/user}","branches_url":"https://api.github.com/repos/tweag/rules_nixpkgs/branches{/branch}","tags_url":"https://api.github.com/repos/tweag/rules_nixpkgs/tags","blobs_url":"https://api.github.com/repos/tweag/rules_nixpkgs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tweag/rules_nixpkgs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tweag/rules_nixpkgs/git/refs{/sha}","trees_url":"https://api.github.com/repos/tweag/rules_nixpkgs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tweag/rules_nixpkgs/statuses/{sha}","languages_url":"https://api.github.com/repos/tweag/rules_nixpkgs/languages","stargazers_url":"https://api.github.com/repos/tweag/rules_nixpkgs/stargazers","contributors_url":"https://api.github.com/repos/tweag/rules_nixpkgs/contributors","subscribers_url":"https://api.github.com/repos/tweag/rules_nixpkgs/subscribers","subscription_url":"https://api.github.com/repos/tweag/rules_nixpkgs/subscription","commits_url":"https://api.github.com/repos/tweag/rules_nixpkgs/commits{/sha}","git_commits_url":"https://api.github.com/repos/tweag/rules_nixpkgs/git/commits{/sha}","comments_url":"https://api.github.com/repos/tweag/rules_nixpkgs/comments{/number}","issue_comment_url":"https://api.github.com/repos/tweag/rules_nixpkgs/issues/comments{/number}","contents_url":"https://api.github.com/repos/tweag/rules_nixpkgs/contents/{+path}","compare_url":"https://api.github.com/repos/tweag/rules_nixpkgs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tweag/rules_nixpkgs/merges","archive_url":"https://api.github.com/repos/tweag/rules_nixpkgs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tweag/rules_nixpkgs/downloads","issues_url":"https://api.github.com/repos/tweag/rules_nixpkgs/issues{/number}","pulls_url":"https://api.github.com/repos/tweag/rules_nixpkgs/pulls{/number}","milestones_url":"https://api.github.com/repos/tweag/rules_nixpkgs/milestones{/number}","notifications_url":"https://api.github.com/repos/tweag/rules_nixpkgs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tweag/rules_nixpkgs/labels{/name}","releases_url":"https://api.github.com/repos/tweag/rules_nixpkgs/releases{/id}","deployments_url":"https://api.github.com/repos/tweag/rules_nixpkgs/deployments","created_at":"2017-12-10T08:53:48Z","updated_at":"2018-10-26T05:19:34Z","pushed_at":"2018-11-11T00:09:39Z","git_url":"git://github.com/tweag/rules_nixpkgs.git","ssh_url":"git@github.com:tweag/rules_nixpkgs.git","clone_url":"https://github.com/tweag/rules_nixpkgs.git","svn_url":"https://github.com/tweag/rules_nixpkgs","homepage":null,"size":88,"stargazers_count":27,"watchers_count":27,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"archived":false,"open_issues_count":3,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":6,"open_issues":3,"watchers":27,"default_branch":"master"}},"base":{"label":"tweag:master","ref":"master","sha":"fd9adeb5be345108a10bad97994f45a6c4dc3b42","user":{"login":"tweag","id":6057932,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYwNTc5MzI=","avatar_url":"https://avatars3.githubusercontent.com/u/6057932?v=4","gravatar_id":"","url":"https://api.github.com/users/tweag","html_url":"https://github.com/tweag","followers_url":"https://api.github.com/users/tweag/followers","following_url":"https://api.github.com/users/tweag/following{/other_user}","gists_url":"https://api.github.com/users/tweag/gists{/gist_id}","starred_url":"https://api.github.com/users/tweag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tweag/subscriptions","organizations_url":"https://api.github.com/users/tweag/orgs","repos_url":"https://api.github.com/users/tweag/repos","events_url":"https://api.github.com/users/tweag/events{/privacy}","received_events_url":"https://api.github.com/users/tweag/received_events","type":"Organization","site_admin":false},"repo":{"id":113735960,"node_id":"MDEwOlJlcG9zaXRvcnkxMTM3MzU5NjA=","name":"rules_nixpkgs","full_name":"tweag/rules_nixpkgs","private":false,"owner":{"login":"tweag","id":6057932,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYwNTc5MzI=","avatar_url":"https://avatars3.githubusercontent.com/u/6057932?v=4","gravatar_id":"","url":"https://api.github.com/users/tweag","html_url":"https://github.com/tweag","followers_url":"https://api.github.com/users/tweag/followers","following_url":"https://api.github.com/users/tweag/following{/other_user}","gists_url":"https://api.github.com/users/tweag/gists{/gist_id}","starred_url":"https://api.github.com/users/tweag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tweag/subscriptions","organizations_url":"https://api.github.com/users/tweag/orgs","repos_url":"https://api.github.com/users/tweag/repos","events_url":"https://api.github.com/users/tweag/events{/privacy}","received_events_url":"https://api.github.com/users/tweag/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/tweag/rules_nixpkgs","description":"Rules for importing Nixpkgs packages into Bazel.","fork":false,"url":"https://api.github.com/repos/tweag/rules_nixpkgs","forks_url":"https://api.github.com/repos/tweag/rules_nixpkgs/forks","keys_url":"https://api.github.com/repos/tweag/rules_nixpkgs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tweag/rules_nixpkgs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tweag/rules_nixpkgs/teams","hooks_url":"https://api.github.com/repos/tweag/rules_nixpkgs/hooks","issue_events_url":"https://api.github.com/repos/tweag/rules_nixpkgs/issues/events{/number}","events_url":"https://api.github.com/repos/tweag/rules_nixpkgs/events","assignees_url":"https://api.github.com/repos/tweag/rules_nixpkgs/assignees{/user}","branches_url":"https://api.github.com/repos/tweag/rules_nixpkgs/branches{/branch}","tags_url":"https://api.github.com/repos/tweag/rules_nixpkgs/tags","blobs_url":"https://api.github.com/repos/tweag/rules_nixpkgs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tweag/rules_nixpkgs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tweag/rules_nixpkgs/git/refs{/sha}","trees_url":"https://api.github.com/repos/tweag/rules_nixpkgs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tweag/rules_nixpkgs/statuses/{sha}","languages_url":"https://api.github.com/repos/tweag/rules_nixpkgs/languages","stargazers_url":"https://api.github.com/repos/tweag/rules_nixpkgs/stargazers","contributors_url":"https://api.github.com/repos/tweag/rules_nixpkgs/contributors","subscribers_url":"https://api.github.com/repos/tweag/rules_nixpkgs/subscribers","subscription_url":"https://api.github.com/repos/tweag/rules_nixpkgs/subscription","commits_url":"https://api.github.com/repos/tweag/rules_nixpkgs/commits{/sha}","git_commits_url":"https://api.github.com/repos/tweag/rules_nixpkgs/git/commits{/sha}","comments_url":"https://api.github.com/repos/tweag/rules_nixpkgs/comments{/number}","issue_comment_url":"https://api.github.com/repos/tweag/rules_nixpkgs/issues/comments{/number}","contents_url":"https://api.github.com/repos/tweag/rules_nixpkgs/contents/{+path}","compare_url":"https://api.github.com/repos/tweag/rules_nixpkgs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tweag/rules_nixpkgs/merges","archive_url":"https://api.github.com/repos/tweag/rules_nixpkgs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tweag/rules_nixpkgs/downloads","issues_url":"https://api.github.com/repos/tweag/rules_nixpkgs/issues{/number}","pulls_url":"https://api.github.com/repos/tweag/rules_nixpkgs/pulls{/number}","milestones_url":"https://api.github.com/repos/tweag/rules_nixpkgs/milestones{/number}","notifications_url":"https://api.github.com/repos/tweag/rules_nixpkgs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tweag/rules_nixpkgs/labels{/name}","releases_url":"https://api.github.com/repos/tweag/rules_nixpkgs/releases{/id}","deployments_url":"https://api.github.com/repos/tweag/rules_nixpkgs/deployments","created_at":"2017-12-10T08:53:48Z","updated_at":"2018-10-26T05:19:34Z","pushed_at":"2018-11-11T00:09:39Z","git_url":"git://github.com/tweag/rules_nixpkgs.git","ssh_url":"git@github.com:tweag/rules_nixpkgs.git","clone_url":"https://github.com/tweag/rules_nixpkgs.git","svn_url":"https://github.com/tweag/rules_nixpkgs","homepage":null,"size":88,"stargazers_count":27,"watchers_count":27,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"archived":false,"open_issues_count":3,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":6,"open_issues":3,"watchers":27,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tweag/rules_nixpkgs/pulls/40"},"html":{"href":"https://github.com/tweag/rules_nixpkgs/pull/40"},"issue":{"href":"https://api.github.com/repos/tweag/rules_nixpkgs/issues/40"},"comments":{"href":"https://api.github.com/repos/tweag/rules_nixpkgs/issues/40/comments"},"review_comments":{"href":"https://api.github.com/repos/tweag/rules_nixpkgs/pulls/40/comments"},"review_comment":{"href":"https://api.github.com/repos/tweag/rules_nixpkgs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tweag/rules_nixpkgs/pulls/40/commits"},"statuses":{"href":"https://api.github.com/repos/tweag/rules_nixpkgs/statuses/2582aa24d2e6d374c206fc40df968b95dc971fc1"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"Profpatsch"}}