Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using nix_file_deps in rules_haskell_toolchains extension causes error #2214

Open
avdv opened this issue Jun 30, 2024 · 0 comments
Open

Using nix_file_deps in rules_haskell_toolchains extension causes error #2214

avdv opened this issue Jun 30, 2024 · 0 comments

Comments

@avdv
Copy link
Member

avdv commented Jun 30, 2024

Describe the bug
Declaring a toolchain using the nix_haskell_toolchains.new extension with nix_file_deps:

nix_haskell_toolchains = use_extension(
    "@rules_haskell_nix//extensions:nix_haskell_toolchains.bzl",
    "nix_haskell_toolchains",
)
nix_haskell_toolchains.new(
    attribute_path = "",
    ghcopts = GHC_OPTS,
    nix_file = "//nix:ghc.nix",
    nix_file_deps = [
        "//:nixpkgs.nix",
        "//:flake.lock",
    ],
    nixopts = [
        "--argstr",
        "ghcVersion",
        GHC_VERSION,
    ],
    repository = "@nixpkgs",
    version = GHC_VERSION,
)

causes this error:

ERROR: <builtin>: @@rules_haskell_nix~//extensions:rules_haskell_nix~~nix_haskell_toolchains~replay_0.2_0_ghc_nixpkgs: expected value of type 'string' for dict value element, but got Label("//:nixpkgs.nix") (Label)
ERROR: Traceback (most recent call last):
        File "/build/output/external/rules_haskell_nix~/extensions/nix_haskell_toolchains.bzl", line 176, column 28, in _nix_haskell_toolchains_impl
                nixpkgs_package(
        File "/build/output/external/rules_nixpkgs_core~/nixpkgs.bzl", line 723, column 21, in nixpkgs_package
                _nixpkgs_package(**kwargs)
Error in repository_rule: failed to instantiate '_nixpkgs_package' from this module extension

To Reproduce
See above.

Expected behavior
This should work fine.

Environment

  • OS name + version: NixOS 23.11
  • Bazel version: 7.1.0
  • Version of the rules: 0.19

Additional context
The nixpkgs_package macro takes a hidden _bzlmod parameter here:
https://github.com/tweag/rules_nixpkgs/blob/ecd3028f3a586a5bdd3eeb73d3d621dc822a10a7/core/nixpkgs.bzl#L684-L695

    if kwargs.pop("_bzlmod", None):
        # The workaround to map canonicalized labels to the user provided
        # string representation to enable location expansion does not work when
        # nixpkgs_package is invoked from a module extension, because module
        # extension tags cannot be wrapped in macros.
        # Until we find a solution to this issue, we provide the canonicalized
        # label as a string. Location expansion will have to be performed on
        # canonicalized labels until a better solution is found.
        # TODO[AH] Support proper location expansion in module extension.
        nix_file_deps = {dep: str(dep) for dep in nix_file_deps} if nix_file_deps else {}
    else:
        nix_file_deps = {dep: dep for dep in nix_file_deps} if nix_file_deps else {}

This parameter should be set to true when calling this macro from an extension.

@avdv avdv added the type: bug label Jun 30, 2024
@avdv avdv changed the title Using nix_file_deps in rules_haskell_toolchains` extension causes error Using nix_file_deps in rules_haskell_toolchains extension causes error Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant