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

Generated Nix expression references out-of-scope pkgs #40

Closed
isomorpheme opened this issue Dec 5, 2023 · 4 comments · Fixed by #52
Closed

Generated Nix expression references out-of-scope pkgs #40

isomorpheme opened this issue Dec 5, 2023 · 4 comments · Fixed by #52

Comments

@isomorpheme
Copy link
Contributor

Minimal repro here:

https://gist.github.com/isomorpheme/514b826ca0f9bf2ee28aa5ca27863d8b

Running nix build on that flake will produce an error like

error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'my-example-haskell-lib-0.1.0.0'
         whose name attribute is located at /nix/store/7adgvk5zdfq4pwrhsm3n9lzypb12gw0g-source/pkgs/stdenv/generic/make-derivation.nix:348:7

       … while evaluating attribute 'propagatedBuildInputs' of derivation 'my-example-haskell-lib-0.1.0.0'

         at /nix/store/7adgvk5zdfq4pwrhsm3n9lzypb12gw0g-source/pkgs/stdenv/generic/make-derivation.nix:402:7:

          401|       depsHostHostPropagated      = elemAt (elemAt propagatedDependencies 1) 0;
          402|       propagatedBuildInputs       = elemAt (elemAt propagatedDependencies 1) 1;
             |       ^
          403|       depsTargetTargetPropagated  = elemAt (elemAt propagatedDependencies 2) 0;

       error: undefined variable 'pkgs'

       at /nix/store/4hnqbxmqsjm7gqngszp1xvgx87i3bh5d-cabal2nix-tz-0.1.3.6/default.nix:23:34:

           22|   ];
           23|   preConfigure = "export TZDIR=${pkgs.tzdata}/share/zoneinfo";
             |                                  ^
           24|   homepage = "https://github.com/ysangkok/haskell-tz";

The top-level trigger is the dependency on tz; commenting it in my-example-haskell-lib makes the build succeed.

The custom preConfigure seems to come from here, but if so I have no idea how the ${pkgs.tzdata} bit wasn't interpolated already. In hackage-packages.nix it also shows up, but there it's fine because pkgs is bound at the top of the file. The generated default.nix that triggers the error doesn't have this structure.

I've tried using cabal2NixArgsOverrides as a workaround, but it doesn't seem to work (I might've been using it wrong, though).

This may be an upstream issue with cabal2nix, but I couldn't tell for sure, so I'm starting here.

@isomorpheme
Copy link
Contributor Author

Ah, it's actually added by cabal2nix itself: https://github.com/NixOS/cabal2nix/blob/2099a1f4594f621bb1a2879b793b860aefe4c027/cabal2nix/src/Distribution/Nixpkgs/Haskell/FromCabal/PostProcess.hs#L177

So I think this is indeed an upstream issue after all.

@cdepillabout
Copy link
Owner

@isomorpheme Thanks for looking into this.

I sent a PR to cabal2nix that should somewhat fix this: NixOS/cabal2nix#611.

This problem will require a separate fix in stacklock2nix as well.

@isomorpheme
Copy link
Contributor Author

That was fast, thank you!

@cdepillabout
Copy link
Owner

This has made its way to Nixpkgs: NixOS/nixpkgs@0c2ff42

But we still need this same fix in stacklock2nix, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants