nh2 / static-haskell-nix

easily build most Haskell programs into fully static Linux executables
388 stars 36 forks source link

Simple project build fails due to `callCabal2nix` being a function, not a set #12

Closed talw closed 5 years ago

talw commented 5 years ago

Can't build a simple project due to callCabal2nix being a function and not a derivation.

I'm using commit: 9781df8a48eade302d159ce63a7ab0c30247788c from 1st of March 2019

Trying to build fails on this error:

error: while evaluating the attribute 'callCabal2nix' at /nix/store/5nj7vgd7spdcvxs47gpv58nqjs76vsla-source/lib/attrsets.nix:200:46:
while evaluating anonymous function at /.../static-haskell-nix/survey/default.nix:680:25, called from /nix/store/5nj7vgd7spdcvxs47gpv58nqjs76vsla-source/lib/attrsets.nix:200:54:
while evaluating 'isExecutable' at /.../static-haskell-nix/survey/default.nix:58:18, called from /home/talw/code/static-haskell-nix/survey/default.nix:681:10:
while evaluating 'overrideCabal' at /nix/store/5nj7vgd7spdcvxs47gpv58nqjs76vsla-source/pkgs/development/haskell-modules/lib.nix:37:24, called from /home/talw/code/static-haskell-nix/survey/default.nix:59:6:
value is a function while a set was expected, at /nix/store/5nj7vgd7spdcvxs47gpv58nqjs76vsla-source/pkgs/development/haskell-modules/lib.nix:37:28

Looking in survey/default.nix I found:

  haskellPackages =
    lib.mapAttrs (name: value:
      if isExecutable value then statify value else value
    ) haskellPackagesWithLibsReadyForStaticLinking;

The error was that isExecutable expects to get a set but got a function. So I traced to see on which name it happens:

  haskellPackages =
    lib.mapAttrs (name: value:
      if isExecutable (builtins.trace name value) then statify value else value
    ) haskellPackagesWithLibsReadyForStaticLinking;

And found it to be: trace: callCabal2nix

The following changed circumvented the error, but I'm not sure why this happens of what is the correct solution:

  haskellPackages =
    lib.mapAttrs (name: value:
      if name != "callCabal2nix" && isExecutable value then statify value else value
    ) haskellPackagesWithLibsReadyForStaticLinking;

Note that I passed to survey the exact same nixpkgs as did the static_stack example so no surprises there.

  nixpkgsForStatic = import (fetchTarball https://github.com/NixOS/nixpkgs/archive/88ae8f7d55efa457c95187011eb410d097108445.tar.gz) {};

  staticPkgs = (survey {
    normalPkgs = nixpkgsForStatic;
    overlays = [pyopenssl-fix-test-buffer-size-overlay];
  }).pkgs;

  staticHaskPkgs = (survey {
    normalPkgs = staticPkgs;
  }).haskellPackages;

  staticDrv = staticHaskPkgs.callCabal2nix "experiment" ./. {};

I wonder if this problem is replicated for other people.

talw commented 5 years ago

Problem was resolved when I defined my project inside survey with the other static Haskell packages.

sboosali commented 5 years ago

i assume it's because callCabal2nix was added to haskellPackages in a later version has nix packages send the pinned one.

maybe we need to add more attrs to some blacklist? like [ "callCabal2nix" "callPackage" "callHackage" ].

On Fri, Mar 1, 2019, 23:01 Tal Walter notifications@github.com wrote:

Closed #12 https://github.com/nh2/static-haskell-nix/issues/12.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nh2/static-haskell-nix/issues/12#event-2175627889, or mute the thread https://github.com/notifications/unsubscribe-auth/ACNoMWxaYmPXdFoXAA35PD472HO51dYTks5vSiG9gaJpZM4baL9Z .