Skip to content

Commit

Permalink
Add sub-modules from rules_nixpkgs
Browse files Browse the repository at this point in the history
  • Loading branch information
avdv committed Mar 16, 2022
1 parent 04dff55 commit cb4f874
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 25 deletions.
3 changes: 0 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ register_toolchains(
"//:c2hs-toolchain",
)

load("@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl", "rules_nixpkgs_dependencies")
rules_nixpkgs_dependencies(local = "../rules_nixpkgs")

load("//bazel_tools/dev_env_tool:dev_env_tool.bzl", "dadew", "dev_env_tool")
load(
"@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl",
Expand Down
87 changes: 65 additions & 22 deletions deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ rules_haskell_patches = [
# This should be upstreamed
"@com_github_digital_asset_daml//bazel_tools:haskell-ghc-includes.patch",
]
rules_nixpkgs_version = "81f61c4b5afcf50665b7073f7fce4c1755b4b9a3"
rules_nixpkgs_sha256 = "33fd540d0283cf9956d0a5a640acb1430c81539a84069114beaf9640c96d221a"
rules_nixpkgs_name = "io_tweag_rules_nixpkgs"
rules_nixpkgs_version = "b4967da9f979bb9802d1a70e80ba3e8afae1d20b"
rules_nixpkgs_sha256 = "47b7b8800115749904f598c8962ff285f1727a5654821a47154cbf34a57a5353"
rules_nixpkgs_patches = [
# On CI and locally we observe occasional segmantation faults
# of nix. A known issue since Nix 2.2.2 is that HTTP2 support
Expand Down Expand Up @@ -107,27 +108,69 @@ def daml_deps():
sha256 = rules_haskell_sha256,
)

native.local_repository(
name = "io_tweag_rules_nixpkgs",
path = "../rules_nixpkgs",
)
if rules_nixpkgs_name not in native.existing_rules():
http_archive(
name = "io_tweag_rules_nixpkgs",
strip_prefix = "rules_nixpkgs-%s" % rules_nixpkgs_version,
urls = ["https://github.com/tweag/rules_nixpkgs/archive/%s.tar.gz" % rules_nixpkgs_version],
sha256 = rules_nixpkgs_sha256,
#patches = rules_nixpkgs_patches,
#patch_args = ["-p1"],
)

#http_archive(
# name = "io_tweag_rules_nixpkgs",
# strip_prefix = "rules_nixpkgs-44016ae08089c0857174168eadf81a07fe2400f7",
# urls = ["https://github.com/tweag/rules_nixpkgs/archive/44016ae08089c0857174168eadf81a07fe2400f7.tar.gz"],
# sha256 = "62ca71dfc05047aca0622691a7c66df97623e7f313cefe87f2219d8726034c4c",
#)

#if "io_tweag_rules_nixpkgs" not in native.existing_rules():
# http_archive(
# name = "io_tweag_rules_nixpkgs",
# strip_prefix = "rules_nixpkgs-%s" % rules_nixpkgs_version,
# urls = ["https://github.com/tweag/rules_nixpkgs/archive/%s.tar.gz" % rules_nixpkgs_version],
# sha256 = rules_nixpkgs_sha256,
# patches = rules_nixpkgs_patches,
# patch_args = ["-p1"],
# )
# the following complication is due to migrating to `bzlmod`.

This comment has been minimized.

Copy link
@aherrmann

aherrmann Mar 16, 2022

Contributor

Was it necessary to duplicate this here, or could this have been done by calling rules_nixpkgs_dependencies in WORKSPACE as well?

This comment has been minimized.

Copy link
@avdv

avdv Mar 16, 2022

Author Contributor

Yes, it would have been perfectly possible to call rules_nixpkgs_dependencies() in the WORKSPACE file (actually that is what I did at first to keep things simple).

But AFAIU, they do not want users of daml having to deal with transitive dependencies, everything should just work by doing:

load("@com_github_digital_asset_daml//:deps.bzl", "daml_deps")
daml_deps()

@aherrmann

# fetch extracted submodules as external repositories from an existing source tree, based on the import type.
rules_nixpkgs = native.existing_rule(rules_nixpkgs_name)

kind = rules_nixpkgs.get("kind")

strip_prefix = rules_nixpkgs.get("strip_prefix", "")
if strip_prefix:
strip_prefix += "/"

for name, prefix in [
("rules_nixpkgs_core", "core"),
("rules_nixpkgs_cc", "toolchains/cc"),
("rules_nixpkgs_java", "toolchains/java"),
("rules_nixpkgs_python", "toolchains/python"),
("rules_nixpkgs_posix", "toolchains/posix"),
]:
# case analysis in inner loop to reduce code duplication
if kind == "local_repository":
path = rules_nixpkgs.get("path")
maybe(native.local_repository, name, path = "{}/{}".format(path, prefix))
elif kind == "http_archive":
maybe(
http_archive,
name,
strip_prefix = strip_prefix + prefix,
# there may be more attributes needed. please submit a pull request to support your use case.
url = rules_nixpkgs.get("url"),
urls = rules_nixpkgs.get("urls"),
sha256 = rules_nixpkgs.get("sha256"),
)
elif kind == "git_repository":
maybe(
git_repository,
name,
strip_prefix = strip_prefix + prefix,
# there may be more attributes needed. please submit a pull request to support your use case.
remote = rules_nixpkgs.get("remote"),
commit = rules_nixpkgs.get("commit"),
branch = rules_nixpkgs.get("branch"),
tag = rules_nixpkgs.get("tag"),
shallow_since = rules_nixpkgs.get("shallow_since"),
)
else:
errormsg = [
"Could not find any import type for `rules_nixpkgs`.",
"This should not happen. If you encounter this using the latest release",
"of `rules_nixpkgs`, please file an issue describing your use case:",
"https://github.com/tweag/rules_nixpkgs/issues",
"or submit a pull request with corrections:",
"https://github.com/tweag/rules_nixpkgs/pulls",
]
fail("\n".join(errormsg))

if "com_github_madler_zlib" not in native.existing_rules():
http_archive(
Expand Down

0 comments on commit cb4f874

Please sign in to comment.