- 
                Notifications
    You must be signed in to change notification settings 
- Fork 87
Open
Labels
Description
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.