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

cabal2nix evaluation failures #73

Open
Gabriella439 opened this issue Jan 14, 2020 · 29 comments
Open

cabal2nix evaluation failures #73

Gabriella439 opened this issue Jan 14, 2020 · 29 comments

Comments

@Gabriella439
Copy link

Here's the reproduction:

let
  compiler = "ghc865";

  nixpkgs = builtins.fetchTarball {
    url    = "https://github.com/nh2/nixpkgs/archive/11aa987ea5b5a593c9ca7a38b391804959f905e5.tar.gz";
    sha256 = "1wns6051fxpgmszyxjvk7020zzhljjxqxkrnqmyd3b6fah7q4vny";
  };

  static-haskell-nix = builtins.fetchTarball {
    url    = "https://github.com/nh2/static-haskell-nix/archive/d24dea3d46a727e1cd93e67458ce2768109efe0a.tar.gz";

    sha256 = "0ri4r77md77kmbqmx0j3h0paj538zpq4hki7vy8ycpwssm2xd442";
  };

  overlay = pkgsNew: pkgsOld: {
    haskell = pkgsOld.haskell // {
      packages = pkgsOld.haskell.packages // {
        "${compiler}" = pkgsOld.haskell.packages."${compiler}".override (old: {
            overrides = pkgsNew.haskell.lib.packageSourceOverrides {
              dhall = "1.27";
            };
          }
        );
      };
    };
  };

  normalPkgs = import nixpkgs {
    system = "x86_64-linux";

    config = { };

    overlays = [ overlay ];
  };

  staticHaskell = import "${static-haskell-nix}/survey/default.nix" {
    inherit compiler normalPkgs;
  };

in
  staticHaskell.all.dhall

Here's the evaluation failure:

$ nix build --file ./minimal.nix --show-trace
error: while evaluating the file '/root/dhall-haskell/minimal.nix':
while evaluating the attribute 'all.dhall' at /nix/store/2yha1cvdl0d3l9p8zv00qhnbrkfx41fr-source/survey/default.nix:1263:32:
while evaluating the attribute 'dhall' at undefined position:
while evaluating anonymous function at /nix/store/2yha1cvdl0d3l9p8zv00qhnbrkfx41fr-source/survey/default.nix:1245:35, called from undefined position:
while evaluating 'isProperHaskellPackage' at /nix/store/2yha1cvdl0d3l9p8zv00qhnbrkfx41fr-source/survey/default.nix:84:28, called from /nix/store/2yha1cvdl0d3l9p8zv00qhnbrkfx41fr-source/survey/default.nix:1246:15:
while evaluating 'isDerivation' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/attrsets.nix:305:18, called from /nix/store/2yha1cvdl0d3l9p8zv00qhnbrkfx41fr-source/survey/default.nix:85:5:
while evaluating anonymous function at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/lib.nix:48:54, called from undefined position:
while evaluating 'callPackageKeepDeriver' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/make-package-set.nix:157:33, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/lib.nix:53:10:
while evaluating 'overrideCabal' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/lib.nix:37:24, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/make-package-set.nix:158:5:
while evaluating 'callPackage' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/make-package-set.nix:114:22, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/make-package-set.nix:158:20:
while evaluating 'callPackageWithScope' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/make-package-set.nix:74:37, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/make-package-set.nix:114:28:
while evaluating 'makeOverridable' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:67:24, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/make-package-set.nix:97:8:
while evaluating 'drvScope' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/make-package-set.nix:87:18, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:69:12:
while evaluating the attribute 'nativeBuildInputs' of the derivation 'cabal2nix-dhall-1.27' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/make-package-set.nix:126:7:
while evaluating 'getOutput' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/attrsets.nix:464:23, called from undefined position:
while evaluating anonymous function at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/stdenv/generic/make-derivation.nix:133:17, called from undefined position:
while evaluating the attribute 'cabal2nix' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/top-level/all-packages.nix:1262:3:
while evaluating 'overrideCabal' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/lib.nix:37:24, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/top-level/all-packages.nix:1262:15:
while evaluating 'override' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:73:20, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/lib.nix:37:28:
while evaluating 'makeOverridable' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:67:24, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:73:29:
while evaluating 'drvScope' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/make-package-set.nix:87:18, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:69:12:
while evaluating anonymous function at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/hackage-packages.nix:45954:6, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/make-package-set.nix:87:27:
while evaluating 'mkDerivation' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/lib.nix:38:20, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/hackage-packages.nix:45960:6:
while evaluating 'override' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:73:20, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/lib.nix:38:25:
while evaluating 'makeOverridable' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:67:24, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:73:29:
while evaluating anonymous function at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/generic-builder.nix:12:1, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:69:12:
while evaluating 'fix' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/fixed-points.nix:19:9, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/generic-builder.nix:240:4:
while evaluating anonymous function at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/generic-builder.nix:240:20, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/fixed-points.nix:19:20:
while evaluating 'optionalAttrs' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/attrsets.nix:331:25, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/development/haskell-modules/generic-builder.nix:511:4:
while evaluating the attribute 'configureFlags' of the derivation 'nix-2.3.1' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/tools/package-management/nix/default.nix:28:14:
while evaluating the attribute 'configurePhase' of the derivation 'busybox-1.30.1-x86_64-unknown-linux-musl' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/stdenv/generic/make-derivation.nix:197:11:
while evaluating the attribute 'cc.targetPrefix' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/stdenv/generic/default.nix:148:14:
while evaluating the attribute 'gcc' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/top-level/all-packages.nix:7605:3:
while evaluating 'addMetaAttrs' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/meta.nix:15:28, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/top-level/all-packages.nix:7765:10:
while evaluating 'wrapCC' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/top-level/all-packages.nix:8625:12, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/top-level/all-packages.nix:7765:19:
while evaluating 'wrapCCWith' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/top-level/all-packages.nix:8604:5, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/top-level/all-packages.nix:8625:16:
while evaluating 'callPackageWith' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:108:35, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/top-level/all-packages.nix:8613:7:
while evaluating 'makeOverridable' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:67:24, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:112:8:
while evaluating anonymous function at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/build-support/cc-wrapper/default.nix:8:1, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:69:12:
while evaluating the attribute 'patches' of the derivation 'musl-1.1.22-x86_64-unknown-linux-musl' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/stdenv/generic/make-derivation.nix:197:11:
while evaluating the attribute 'nativeBuildInputs' of the derivation '300-relative.patch' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/build-support/fetchurl/default.nix:119:3:
while evaluating 'getOutput' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/attrsets.nix:464:23, called from undefined position:
while evaluating anonymous function at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/stdenv/generic/make-derivation.nix:133:17, called from undefined position:
while evaluating 'override' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:73:20, called from /nix/store/2yha1cvdl0d3l9p8zv00qhnbrkfx41fr-source/survey/default.nix:697:14:
while evaluating 'makeOverridable' at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:67:24, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:73:29:
while evaluating anonymous function at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:77:28, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:69:12:
while evaluating anonymous function at /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/pkgs/tools/networking/curl/default.nix:1:1, called from /nix/store/7fjx5cza1ijdf6bsnchqn8g5zd0hza33-source/lib/customisation.nix:77:35:
while evaluating 'statify_zlib' at /nix/store/2yha1cvdl0d3l9p8zv00qhnbrkfx41fr-source/survey/default.nix:459:18, called from /nix/store/2yha1cvdl0d3l9p8zv00qhnbrkfx41fr-source/survey/default.nix:697:41:
attribute 'override' missing, at /nix/store/2yha1cvdl0d3l9p8zv00qhnbrkfx41fr-source/survey/default.nix:460:6

I believe this is not the same thing as #9 since that is a build failure whereas this is an evaluation failure.

@nh2
Copy link
Owner

nh2 commented Jan 30, 2020

Hey Gabriel, thanks for the report.

The problem is in this line:

(zlib_drv.override {

The issue here seems to be that, probably via cabal2nix -> fetchurl -> curl -> zlib, somewhere zlib.static is used, and that is not overridable:

$ nix-shell -p 'pkgs.zlib.override {}'
# works fine

$ nix-shell -p 'pkgs.zlib.static.override {}'
error: attribute 'override' missing, at (string):1:94

Now I just need to find out what to do about it...

@nh2
Copy link
Owner

nh2 commented Jan 30, 2020

It's going to be this:

https://github.com/nh2/nixpkgs/blob/11aa987ea5b5a593c9ca7a38b391804959f905e5/pkgs/top-level/static.nix#L86-L93

{
 zlib = (super.zlib.override {
    static = true;
    shared = false;

    # Don’t use new stdenv zlib because
    # it doesn’t like the --disable-shared flag
    stdenv = super.stdenv;
  }).static;
}

This was already accidentally fixed in nixpkgs master with https://github.com/NixOS/nixpkgs/pull/74485/files#diff-d125f8cf97a8da782a42f2f648415cd9L92 which removes the use of .static in favour of splitStaticOutput = false; inside the .override.

@nh2
Copy link
Owner

nh2 commented Jan 30, 2020

FYI @malbarbo @dtzWill @matthewbauer Check out the above and the previous two comments, it appears that we must never use .static outputs in things like static.nix because they are not overridable.

@nh2
Copy link
Owner

nh2 commented Jan 30, 2020

When I cherry-pick that, or use nixpkgs master, the next challenge I face is this infinite recursion:

error: while evaluating the attribute 'haskellPackages.dhall' at undefined position:
while evaluating anonymous function at /home/niklas/src/haskell/static-haskell-nix-review/survey/default.nix:1252:20, called from undefined position:
while evaluating 'isProperHaskellPackage' at /home/niklas/src/haskell/static-haskell-nix-review/survey/default.nix:84:28, called from /home/niklas/src/haskell/static-haskell-nix-review/survey/default.nix:1253:19:
while evaluating 'isDerivation' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/attrsets.nix:305:18, called from /home/niklas/src/haskell/static-haskell-nix-review/survey/default.nix:85:5:
while evaluating anonymous function at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/lib.nix:48:54, called from undefined position:
while evaluating 'callPackageKeepDeriver' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/make-package-set.nix:157:33, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/lib.nix:53:10:
while evaluating 'overrideCabal' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/lib.nix:37:24, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/make-package-set.nix:158:5:
while evaluating 'callPackage' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/make-package-set.nix:114:22, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/make-package-set.nix:158:20:
while evaluating 'callPackageWithScope' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/make-package-set.nix:74:37, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/make-package-set.nix:114:28:
while evaluating 'makeOverridable' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/customisation.nix:67:24, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/make-package-set.nix:97:8:
while evaluating 'drvScope' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/make-package-set.nix:87:18, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/customisation.nix:69:12:
while evaluating the attribute 'nativeBuildInputs' of the derivation 'cabal2nix-dhall-1.27' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/make-package-set.nix:126:7:
while evaluating 'getOutput' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/attrsets.nix:464:23, called from undefined position:
while evaluating anonymous function at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:133:17, called from undefined position:
while evaluating the attribute 'cabal2nix' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/top-level/all-packages.nix:1262:3:
while evaluating 'overrideCabal' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/lib.nix:37:24, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/top-level/all-packages.nix:1262:15:
while evaluating 'override' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/customisation.nix:73:20, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/lib.nix:37:28:
while evaluating 'makeOverridable' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/customisation.nix:67:24, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/customisation.nix:73:29:
while evaluating 'drvScope' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/make-package-set.nix:87:18, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/customisation.nix:69:12:
while evaluating anonymous function at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/hackage-packages.nix:45954:6, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/make-package-set.nix:87:27:
while evaluating 'mkDerivation' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/lib.nix:38:20, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/hackage-packages.nix:45960:6:
while evaluating 'override' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/customisation.nix:73:20, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/lib.nix:38:25:
while evaluating 'makeOverridable' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/customisation.nix:67:24, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/customisation.nix:73:29:
while evaluating anonymous function at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/generic-builder.nix:12:1, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/customisation.nix:69:12:
while evaluating 'fix' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/fixed-points.nix:19:9, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/generic-builder.nix:240:4:
while evaluating anonymous function at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/generic-builder.nix:240:20, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/fixed-points.nix:19:20:
while evaluating 'optionalAttrs' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/attrsets.nix:331:25, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/development/haskell-modules/generic-builder.nix:511:4:
while evaluating the attribute 'configureFlags' of the derivation 'nix-2.3.1' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/tools/package-management/nix/default.nix:28:14:
while evaluating the attribute 'configurePhase' of the derivation 'busybox-1.30.1-x86_64-unknown-linux-musl' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:197:11:
while evaluating the attribute 'cc.targetPrefix' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/stdenv/generic/default.nix:148:14:
while evaluating the attribute 'gcc' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/top-level/all-packages.nix:7605:3:
while evaluating 'addMetaAttrs' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/meta.nix:15:28, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/top-level/all-packages.nix:7765:10:
while evaluating 'wrapCC' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/top-level/all-packages.nix:8625:12, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/top-level/all-packages.nix:7765:19:
while evaluating 'wrapCCWith' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/top-level/all-packages.nix:8604:5, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/top-level/all-packages.nix:8625:16:
while evaluating 'callPackageWith' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/customisation.nix:108:35, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/top-level/all-packages.nix:8613:7:
while evaluating 'makeOverridable' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/customisation.nix:67:24, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/customisation.nix:112:8:
while evaluating anonymous function at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/build-support/cc-wrapper/default.nix:8:1, called from /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/lib/customisation.nix:69:12:
while evaluating the attribute 'patches' of the derivation 'musl-1.1.22-x86_64-unknown-linux-musl' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:197:11:
while evaluating the attribute 'nativeBuildInputs' of the derivation '300-relative.patch' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/build-support/fetchurl/default.nix:119:3:
while evaluating the attribute 'propagatedBuildInputs' of the derivation 'curl-7.66.0' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/tools/networking/curl/default.nix:27:3:
while evaluating the attribute 'makeFlags' of the derivation 'zlib-1.2.11-x86_64-unknown-linux-musl' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:197:11:
while evaluating the attribute 'cc.targetPrefix' at /home/niklas/src/haskell/static-haskell-nix-review/nixpkgs/pkgs/stdenv/generic/default.nix:148:14:
infinite recursion encountered, at undefined position

@Gabriella439
Copy link
Author

I think I found the problem: the revision of nixpkgs that static-haskell-nix is currently using is responsible for the infinite recursion. When I update the nixpkgs revision to the latest master the evaluation errors disappear and the only error I have left is the same one as in #29

Here is the change to the reproducing code that now instantiates successfully:

let
  compiler = "ghc865";

  nixpkgs = builtins.fetchTarball {
    url    = "https://github.com/nh2/nixpkgs/archive/83fd89945d355892e0e95747c9a2c519491c1600.tar.gz";
    sha256 = "05jybj66gdzdmjgawa2a72b6pf669rfb6pljhlc3lpyq6dlnw87d";
  };

  static-haskell-nix = builtins.fetchTarball {
    url    = "https://github.com/nh2/static-haskell-nix/archive/c360f2a15f6947b411ecbd7ebaea925f6dbd68df.tar.gz";

    sha256 = "0y6ppiagh6dbvdhhnrq572xnw2yzn6d0gcmajrfdgdfwhsl21g95";
  };

  overlay = pkgsNew: pkgsOld: {
    haskell = pkgsOld.haskell // {
      packages = pkgsOld.haskell.packages // {
        "${compiler}" = pkgsOld.haskell.packages."${compiler}".override (old: {
            overrides = pkgsNew.haskell.lib.packageSourceOverrides {
              dhall = "1.29";
            };
          }
        );
      };
    };
  };

  normalPkgs = import nixpkgs {
    system = "x86_64-linux";

    config = { };

    overlays = [ overlay ];
  };

  staticHaskell = import "${static-haskell-nix}/survey/default.nix" {
    inherit compiler normalPkgs;
  };

in
  staticHaskell.all.dhall

@nh2
Copy link
Owner

nh2 commented Mar 31, 2020

@Gabriel439 Ah that's great.

Do you happen to know which nixpkgs commit is the fix?

I currently cannot (trivially / have not tried yet) upgrade to latest nixpkgs master because my nightly CI shows that the latest master has important Haskell packages like darcs marked as broken:

https://buildkite.com/nh2/static-haskell-nix/builds/341#438409a8-05e1-48a6-8000-b30d5511679f

error: Package ‘darcs-2.14.2’ in /nix/store/lc4aal3h7iqz0cbr6dfpjnrbnig76whk-source/pkgs/development/haskell-modules/hackage-packages.nix:64807 is marked as broken, refusing to evaluate.

My plan so far was to wait until nixpkgs has figured that out, but if it happens to be darcs-specific (as evaluations show only the first error), we could also just disable that for now.

@Gabriella439
Copy link
Author

@nh2: 83fd89945d355892e0e95747c9a2c519491c1600 should work

@nh2
Copy link
Owner

nh2 commented Mar 31, 2020

@Gabriel439 No I mean whether you happen to know which specific commit got rid of the infinite recursion (then I could consider picking it to not break darcs and whatever other Haskell stuff may be broken in current nixpkgs master).

@nh2
Copy link
Owner

nh2 commented Mar 31, 2020

Actually, I think I know which commit is inolved here (fromt the Github backlink further up):

NixOS/nixpkgs#74485 (review)

Sorry, that was for the missing attribute, not the infinite recursion.

@nh2
Copy link
Owner

nh2 commented Mar 31, 2020

Looking into this, I hit NixOS/nixpkgs#83825, but you already took care of that.

Here is the change to the reproducing code that now instantiates successfully:

@Gabriel439 That doesn't work for me:

% nix-instantiate issue-73-investigation-2020-01-31-2.nix -j1
building '/nix/store/42ygzdkbm8w9wlzvp8136vsh1zql4vda-all-cabal-hashes-component-dhall-1.29.drv'...
tar: */dhall/1.29/dhall.json: Not found in archive
tar: */dhall/1.29/dhall.cabal: Not found in archive
tar: Exiting with failure status due to previous errors
builder for '/nix/store/42ygzdkbm8w9wlzvp8136vsh1zql4vda-all-cabal-hashes-component-dhall-1.29.drv' failed with exit code 2
cannot build derivation '/nix/store/cq02ama8wchi75apq3mb8a08dsms8b5j-cabal2nix-dhall-1.29.drv': 1 dependencies couldn't be built
error: build of '/nix/store/cq02ama8wchi75apq3mb8a08dsms8b5j-cabal2nix-dhall-1.29.drv' failed
(use '--show-trace' to show detailed location information)
Command exited with non-zero status 100

@Gabriella439
Copy link
Author

@nh2: Yeah, I didn't get that far yet (I got stuck on the coreutils build failure). I just meant that it fixes the evaluation failure

@Gabriella439
Copy link
Author

@nh2: Also, for that specific error you can probably fix it by s/1.29/1.29.0/

@nh2
Copy link
Owner

nh2 commented Mar 31, 2020

for that specific error you can probably fix it by s/1.29/1.29.0/

Thanks, that's what I needed indeed.

I mean whether you happen to know which specific commit got rid of the infinite recursion

I bisected it; it is commit NixOS/nixpkgs@2645e1a by @madjar that fixed it, merged as part of NixOS/nixpkgs#82345.

Cherry-picking it on top of my current static-haskell-nix-2020-02-05 nixpkgs branch (commit nh2/nixpkgs@0c96026) makes the infinite recursion go away there.

@nh2
Copy link
Owner

nh2 commented Mar 31, 2020

I got stuck on the coreutils build failure

@Gabriel439 What's your plan for that? I'm pretty sure that these days you can use the nix sandbox and nix-daemon also on non-NixOS.

@nh2
Copy link
Owner

nh2 commented Mar 31, 2020

I now got stuck at a bad archive: input doesn't look like a Nix archive error when trying to copy down base-compat:

copying path '/nix/store/a1bsf33rrc7daxna17hbk1y4a61a9qxx-base-compat-0.10.5' from 'https://static-haskell-nix.cachix.org'...
bad archive: input doesn't look like a Nix archive

This was reproducible every time.

This worked around it:

% nix-copy-closure --from static-haskell-nix-ci /nix/store/a1bsf33rrc7daxna17hbk1y4a61a9qxx-base-compat-0.10.5
copying 1 paths...
copying path '/nix/store/a1bsf33rrc7daxna17hbk1y4a61a9qxx-base-compat-0.10.5' from 'ssh://static-haskell-nix-ci'...

Very suspicious.


Edit: Probably this: cachix/cachix#251 (comment)

@nh2
Copy link
Owner

nh2 commented Mar 31, 2020

The next error I encounter is due to krb5 recently breaking (and even more recently re-fixing) musl support: krb5/krb5@b009cca

@nh2
Copy link
Owner

nh2 commented Mar 31, 2020

The next error I encounter is due to krb5 recently breaking (and even more recently re-fixing) musl support: krb5/krb5@b009cca

Problem: As soon as I try to fix that with (edit: actually it needs 2 patches)

diff --git a/pkgs/development/libraries/kerberos/krb5.nix b/pkgs/development/libraries/kerberos/krb5.nix
index 42965c0ad07..8ec04e313f9 100644
--- a/pkgs/development/libraries/kerberos/krb5.nix
+++ b/pkgs/development/libraries/kerberos/krb5.nix
@@ -1,4 +1,5 @@
 { stdenv, fetchurl, pkgconfig, perl, yacc, bootstrap_cmds
+, fetchpatch
 , openssl, openldap, libedit, keyutils
 
 # Extra Arguments
@@ -22,6 +23,14 @@ stdenv.mkDerivation rec {
     sha256 = "121c5xsy3x0i4wdkrpw62yhvji6virbh6n30ypazkp0isws3k4bk";
   };
 
+  patches = [
+    (fetchpatch {
+      url = "https://github.com/krb5/krb5/commit/b009cca2026b615ef5386faa4c0230bc27c4161d.patch";
+      name = "krb5-Fix-typo-in-musl-build-fix.patch";
+      sha256 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+    })
+  ];
+
   outputs = [ "out" "dev" ];
 
   configureFlags = [ "--with-tcl=no" "--localstatedir=/var/lib"]

I get error: infinite recursion encountered, at undefined position again.

Perhaps the fix of NixOS/nixpkgs@2645e1a just made us lucky by removing something similar to fetchpatch and using download (curl?) related things is in fact still broken?

@nh2
Copy link
Owner

nh2 commented Apr 1, 2020

actually it needs 2 patches

PR in https://github.com/benaco/benaco/issues/1196

@nh2
Copy link
Owner

nh2 commented Apr 1, 2020

The next nixpkgs master error is that GHC fails to install (I asked on NixOS/nixpkgs#83164 (comment)):

checking whether we are cross compiling... configure: error: in `/build/ghc-8.6.5':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
note: keeping build directory '/tmp/nix-build-ghc-8.6.5.drv-0'
builder for '/nix/store/82xq6ws6si3f7vkycgjsrl76zkjqz7md-ghc-8.6.5.drv' failed with exit code 1

Details from config.log:

configure:5409: checking for C compiler version
configure:5418: /nix/store/mm81kczg6a8wmi2m67adpggsy7wya98a-gcc-wrapper-9.2.0/bin/cc --version >&5
gcc (GCC) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

configure:5429: $? = 0
configure:5418: /nix/store/mm81kczg6a8wmi2m67adpggsy7wya98a-gcc-wrapper-9.2.0/bin/cc -v >&5
Using built-in specs.
COLLECT_GCC=/nix/store/axzam0k8kswigp137fwcs9v644k32mf5-gcc-9.2.0/bin/gcc
COLLECT_LTO_WRAPPER=/nix/store/axzam0k8kswigp137fwcs9v644k32mf5-gcc-9.2.0/libexec/gcc/x86_64-unknown-linux-musl/9.2.0/lto-wrapper
Target: x86_64-unknown-linux-musl
Configured with: 
Thread model: posix
gcc version 9.2.0 (GCC) 
configure:5429: $? = 0
configure:5418: /nix/store/mm81kczg6a8wmi2m67adpggsy7wya98a-gcc-wrapper-9.2.0/bin/cc -V >&5
gcc: error: unrecognized command line option '-V'
gcc: fatal error: no input files
compilation terminated.
configure:5429: $? = 1
configure:5418: /nix/store/mm81kczg6a8wmi2m67adpggsy7wya98a-gcc-wrapper-9.2.0/bin/cc -qversion >&5
gcc: error: unrecognized command line option '-qversion'; did you mean '--version'?
gcc: fatal error: no input files
compilation terminated.
configure:5429: $? = 1
configure:5449: checking whether the C compiler works
configure:5471: /nix/store/mm81kczg6a8wmi2m67adpggsy7wya98a-gcc-wrapper-9.2.0/bin/cc -fuse-ld=gold   conftest.c  >&5
/nix/store/1aj7gw8zj36rmya0agbrk9wm0w97isdp-binutils-2.31.1/bin/ld.gold: warning: discarding version information for __register_frame_info@GCC_3.0, defined in unused shared library /nix/store/8z497lsggmvgsqjg409s9vmyvjsvys4l-gcc-9.2.0-lib/lib/libgcc_s.so.1 (linked with --as-needed)
/nix/store/1aj7gw8zj36rmya0agbrk9wm0w97isdp-binutils-2.31.1/bin/ld.gold: warning: discarding version information for __deregister_frame_info@GCC_3.0, defined in unused shared library /nix/store/8z497lsggmvgsqjg409s9vmyvjsvys4l-gcc-9.2.0-lib/lib/libgcc_s.so.1 (linked with --as-needed)
configure:5475: $? = 0
configure:5523: result: yes
configure:5526: checking for C compiler default output file name
configure:5528: result: a.out
configure:5534: checking for suffix of executables
configure:5541: /nix/store/mm81kczg6a8wmi2m67adpggsy7wya98a-gcc-wrapper-9.2.0/bin/cc -o conftest -fuse-ld=gold   conftest.c  >&5
/nix/store/1aj7gw8zj36rmya0agbrk9wm0w97isdp-binutils-2.31.1/bin/ld.gold: warning: discarding version information for __register_frame_info@GCC_3.0, defined in unused shared library /nix/store/8z497lsggmvgsqjg409s9vmyvjsvys4l-gcc-9.2.0-lib/lib/libgcc_s.so.1 (linked with --as-needed)
/nix/store/1aj7gw8zj36rmya0agbrk9wm0w97isdp-binutils-2.31.1/bin/ld.gold: warning: discarding version information for __deregister_frame_info@GCC_3.0, defined in unused shared library /nix/store/8z497lsggmvgsqjg409s9vmyvjsvys4l-gcc-9.2.0-lib/lib/libgcc_s.so.1 (linked with --as-needed)
configure:5545: $? = 0
configure:5567: result: 
configure:5589: checking whether we are cross compiling
configure:5597: /nix/store/mm81kczg6a8wmi2m67adpggsy7wya98a-gcc-wrapper-9.2.0/bin/cc -o conftest -fuse-ld=gold   conftest.c  >&5
/nix/store/1aj7gw8zj36rmya0agbrk9wm0w97isdp-binutils-2.31.1/bin/ld.gold: warning: discarding version information for __deregister_frame_info@GCC_3.0, defined in unused shared library /nix/store/8z497lsggmvgsqjg409s9vmyvjsvys4l-gcc-9.2.0-lib/lib/libgcc_s.so.1 (linked with --as-needed)
/nix/store/1aj7gw8zj36rmya0agbrk9wm0w97isdp-binutils-2.31.1/bin/ld.gold: warning: discarding version information for __register_frame_info@GCC_3.0, defined in unused shared library /nix/store/8z497lsggmvgsqjg409s9vmyvjsvys4l-gcc-9.2.0-lib/lib/libgcc_s.so.1 (linked with --as-needed)
configure:5601: $? = 0
configure:5608: ./conftest
./configure: line 5610:  2075 Segmentation fault      ./conftest$ac_cv_exeext
configure:5612: $? = 139
configure:5619: error: in `/build/ghc-8.6.5':
configure:5621: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.

Segmentation fault in the compiled conftest program, not good.

@Gabriella439
Copy link
Author

@nh2: Also, is there any reason why Hydra's CI does not check that these things build correctly? It seems like it would make your life easier if people couldn't introduce nixpkgs changes that break musl builds

@cdepillabout
Copy link
Contributor

@nh2 Here's the PR where the boot compiler was updated: NixOS/nixpkgs#83048

As far as I know, no one is testing that GHC builds with musl when merging in things like this.

For testing things like this, is there some attribute I can give to ofborg to test stuff like this?

For example, on NixOS/nixpkgs#83048, should I have run something like @grahamcofborg build pkgsMusl.haskell.compilers.ghc865binary?

@domenkozar
Copy link
Contributor

@nh2 I've deleted the offending store path, make sure to use Cachix 0.3.7 as it avoids this rare but quite annoying problem :)

@nh2
Copy link
Owner

nh2 commented Apr 1, 2020

Also, is there any reason why Hydra's CI does not check that these things build correctly? It seems like it would make your life easier if people couldn't introduce nixpkgs changes that break musl builds

@Gabriel439 Absolutely, it would make it a lot easier. I guess it would double the amount of building that Hydra would have to do. I imagine in the future we can gather enough musl supporters or infrastructure to make it happen nevertheless.

@nh2
Copy link
Owner

nh2 commented Apr 1, 2020

As far as I know, no one is testing that GHC builds with musl when merging in things like this.

@cdepillabout That's probably right!

For example, on NixOS/nixpkgs#83048, should I have run something like @grahamcofborg build pkgsMusl.haskell.compilers.ghc865binary?

I think that would work, yes. The only problem with ofborg is that it limits builds to 3600 seconds or so. So some larger builds may not complete.

What I'd really want would be to hook my community-sponsored builder into the PR/ofborg infrastructure and have it automatically build the relevant musl musl things. But ofborg currently does not support that.

@nh2
Copy link
Owner

nh2 commented Apr 1, 2020

I've deleted the offending store path, make sure to use Cachix 0.3.7 as it avoids this rare but quite annoying problem :)

@domenkozar Thank you!

I'm on 0.3.7 now.

@bb010g
Copy link

bb010g commented May 20, 2020

Using a MWE conftest-2.c of:

#include <stdio.h>
int main() {
  FILE *f = fopen("conftest.out", "w");
  return ferror(f) || fclose(f) != 0;
}

Compiling with /nix/store/vmg52dd5bdjz8syv73irk4isdyj30x82-gcc-wrapper-9.2.0/bin/cc -fuse-ld=gold -o conftest-2 conftest-2.c prints:

/nix/store/wx62gczhyd5igi8qi63v6l3jnch120x2-binutils-2.31.1/bin/ld.gold: warning: discarding version information for __deregister_frame_info@GCC_3.0, defined in unused shared library /nix/store/fjq3pkc8hllw4h8jfwhc50w3cf5yyd15-gcc-9.2.0-lib/lib/libgcc_s.so.1 (linked with --as-needed)
/nix/store/wx62gczhyd5igi8qi63v6l3jnch120x2-binutils-2.31.1/bin/ld.gold: warning: discarding version information for __register_frame_info@GCC_3.0, defined in unused shared library /nix/store/fjq3pkc8hllw4h8jfwhc50w3cf5yyd15-gcc-9.2.0-lib/lib/libgcc_s.so.1 (linked with --as-needed)
(That cc wrapper)
#! /nix/store/sydxyv59z4dka8h22if5v5p11nl1sf4w-bash-4.4-p23/bin/bash
set -eu -o pipefail +o posix
shopt -s nullglob

if (( "${NIX_DEBUG:-0}" >= 7 )); then
    set -x
fi

path_backup="$PATH"

# That @-vars are substituted separately from bash evaluation makes
# shellcheck think this, and others like it, are useless conditionals.
# shellcheck disable=SC2157
if [[ -n "/nix/store/hbf1ag0ijgjxlfq6b4gs8qiwsgk71wlk-coreutils-8.31" && -n "/nix/store/j41qm139s494q49ajhlz2i9h9g2b5imk-gnugrep-3.4" ]]; then
    PATH="/nix/store/hbf1ag0ijgjxlfq6b4gs8qiwsgk71wlk-coreutils-8.31/bin:/nix/store/j41qm139s494q49ajhlz2i9h9g2b5imk-gnugrep-3.4/bin"
fi

source /nix/store/vmg52dd5bdjz8syv73irk4isdyj30x82-gcc-wrapper-9.2.0/nix-support/utils.bash

# Flirting with a layer violation here.
if [ -z "${NIX_BINTOOLS_WRAPPER_x86_64_unknown_linux_musl_FLAGS_SET:-}" ]; then
    source /nix/store/fl4vnkrxq874zyqzkb415xdhw5npc8vw-binutils-wrapper-2.31.1/nix-support/add-flags.sh
fi

# Put this one second so libc ldflags take priority.
if [ -z "${NIX_CC_WRAPPER_x86_64_unknown_linux_musl_FLAGS_SET:-}" ]; then
    source /nix/store/vmg52dd5bdjz8syv73irk4isdyj30x82-gcc-wrapper-9.2.0/nix-support/add-flags.sh
fi


# Parse command line options and set several variables.
# For instance, figure out if linker flags should be passed.
# GCC prints annoying warnings when they are not needed.
dontLink=0
nonFlagArgs=0
cc1=0
# shellcheck disable=SC2193
[[ "/nix/store/jws4s9kdwvni6c7rfc9vv9z1ycwn6smc-gcc-9.2.0/bin/gcc" = *++ ]] && isCpp=1 || isCpp=0
cppInclude=1

expandResponseParams "$@"
declare -i n=0
nParams=${#params[@]}
while (( "$n" < "$nParams" )); do
    p=${params[n]}
    p2=${params[n+1]:-} # handle `p` being last one
    if [ "$p" = -c ]; then
        dontLink=1
    elif [ "$p" = -S ]; then
        dontLink=1
    elif [ "$p" = -E ]; then
        dontLink=1
    elif [ "$p" = -E ]; then
        dontLink=1
    elif [ "$p" = -M ]; then
        dontLink=1
    elif [ "$p" = -MM ]; then
        dontLink=1
    elif [[ "$p" = -x && "$p2" = *-header ]]; then
        dontLink=1
    elif [[ "$p" = -x && "$p2" = c++* && "$isCpp" = 0 ]]; then
        isCpp=1
    elif [ "$p" = -nostdlib ]; then
        isCpp=-1
    elif [ "$p" = -nostdinc ]; then
        cppInclude=0
    elif [ "$p" = -nostdinc++ ]; then
        cppInclude=0
    elif [[ "$p" != -?* ]]; then
        # A dash alone signifies standard input; it is not a flag
        nonFlagArgs=1
    elif [ "$p" = -cc1 ]; then
        cc1=1
    fi
    n+=1
done

# If we pass a flag like -Wl, then gcc will call the linker unless it
# can figure out that it has to do something else (e.g., because of a
# "-c" flag).  So if no non-flag arguments are given, don't pass any
# linker flags.  This catches cases like "gcc" (should just print
# "gcc: no input files") and "gcc -v" (should print the version).
if [ "$nonFlagArgs" = 0 ]; then
    dontLink=1
fi

# Optionally filter out paths not refering to the store.
if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "$NIX_STORE" ]]; then
    rest=()
    nParams=${#params[@]}
    declare -i n=0
    while (( "$n" < "$nParams" )); do
        p=${params[n]}
        p2=${params[n+1]:-} # handle `p` being last one
        if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
            skip "${p:2}"
        elif [ "$p" = -L ] && badPath "$p2"; then
            n+=1; skip "$p2"
        elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then
            skip "${p:2}"
        elif [ "$p" = -I ] && badPath "$p2"; then
            n+=1; skip "$p2"
        elif [ "$p" = -isystem ] && badPath "$p2"; then
            n+=1; skip "$p2"
        else
            rest+=("$p")
        fi
        n+=1
    done
    # Old bash empty array hack
    params=(${rest+"${rest[@]}"})
fi


# Clear march/mtune=native -- they bring impurity.
if [ "$NIX_x86_64_unknown_linux_musl_ENFORCE_NO_NATIVE" = 1 ]; then
    rest=()
    # Old bash empty array hack
    for p in ${params+"${params[@]}"}; do
        if [[ "$p" = -m*=native ]]; then
            skip "$p"
        else
            rest+=("$p")
        fi
    done
    # Old bash empty array hack
    params=(${rest+"${rest[@]}"})
fi

if [[ "$isCpp" = 1 ]]; then
    if [[ "$cppInclude" = 1 ]]; then
        NIX_x86_64_unknown_linux_musl_CFLAGS_COMPILE+=" ${NIX_x86_64_unknown_linux_musl_CXXSTDLIB_COMPILE:-}"
    fi
    NIX_x86_64_unknown_linux_musl_CFLAGS_LINK+=" $NIX_x86_64_unknown_linux_musl_CXXSTDLIB_LINK"
fi

source /nix/store/vmg52dd5bdjz8syv73irk4isdyj30x82-gcc-wrapper-9.2.0/nix-support/add-hardening.sh

# Add the flags for the C compiler proper.
extraAfter=($NIX_x86_64_unknown_linux_musl_CFLAGS_COMPILE)
extraBefore=(${hardeningCFlags[@]+"${hardeningCFlags[@]}"} $NIX_x86_64_unknown_linux_musl_CFLAGS_COMPILE_BEFORE)

if [ "$dontLink" != 1 ]; then

    # Add the flags that should only be passed to the compiler when
    # linking.
    extraAfter+=($NIX_x86_64_unknown_linux_musl_CFLAGS_LINK)

    # Add the flags that should be passed to the linker (and prevent
    # `ld-wrapper' from adding NIX_x86_64_unknown_linux_musl_LDFLAGS again).
    for i in $NIX_x86_64_unknown_linux_musl_LDFLAGS_BEFORE; do
        extraBefore+=("-Wl,$i")
    done
    for i in $NIX_x86_64_unknown_linux_musl_LDFLAGS; do
        if [ "${i:0:3}" = -L/ ]; then
            extraAfter+=("$i")
        else
            extraAfter+=("-Wl,$i")
        fi
    done
    export NIX_x86_64_unknown_linux_musl_LDFLAGS_SET=1
fi

# As a very special hack, if the arguments are just `-v', then don't
# add anything.  This is to prevent `gcc -v' (which normally prints
# out the version number and returns exit code 0) from printing out
# `No input files specified' and returning exit code 1.
if [ "$*" = -v ]; then
    extraAfter=()
    extraBefore=()
fi

# clang's -cc1 mode is not compatible with most options
# that we would pass. Rather than trying to pass only
# options that would work, let's just remove all of them.
if [ "$cc1" = 1 ]; then
  extraAfter=()
  extraBefore=()
fi

# Optionally print debug info.
if (( "${NIX_DEBUG:-0}" >= 1 )); then
    # Old bash workaround, see ld-wrapper for explanation.
    echo "extra flags before to /nix/store/jws4s9kdwvni6c7rfc9vv9z1ycwn6smc-gcc-9.2.0/bin/gcc:" >&2
    printf "  %q\n" ${extraBefore+"${extraBefore[@]}"}  >&2
    echo "original flags to /nix/store/jws4s9kdwvni6c7rfc9vv9z1ycwn6smc-gcc-9.2.0/bin/gcc:" >&2
    printf "  %q\n" ${params+"${params[@]}"} >&2
    echo "extra flags after to /nix/store/jws4s9kdwvni6c7rfc9vv9z1ycwn6smc-gcc-9.2.0/bin/gcc:" >&2
    printf "  %q\n" ${extraAfter+"${extraAfter[@]}"} >&2
fi

PATH="$path_backup"
# Old bash workaround, see above.
exec /nix/store/jws4s9kdwvni6c7rfc9vv9z1ycwn6smc-gcc-9.2.0/bin/gcc \
    ${extraBefore+"${extraBefore[@]}"} \
    ${params+"${params[@]}"} \
    ${extraAfter+"${extraAfter[@]}"}

And running ./conftest-2 segfaults. Digging in with edb-debugger, ./conftest-2 & /nix/store/yk5jbq48znw9vvd87kkjvxn5rr69j164-musl-1.1.24/lib/libc.so are loaded into memory, and execution flows from conftest-2!_start, to conftest-2!_start_c, to conftest-2!__libc_start_main@plt, to conftest-2!frame_dummy, to conftest-2!__register_frame_info@plt, to conftest-2!frame_dummy, at which point there's the following state:

------------------------------------------------------------------------------
     rax:00000000004005c0 rcx:0000000000000000  rdx:0000000000400580  rbx:00007f5fcff798c0     rflags:0000000000000206
     rsp:00007ffe10fbffe8 rbp:00007ffe10fbfff0  rsi:0000000000402060  rdi:0000000000400818        rip:00000000004005c0
      r8:0000000000400801  r9:0000000000000000  r10:00007f5fcff61ae0  r11:00007f5fcff79b60           o d I t s z a P c
     r12:000000000040076d r13:00007f5fcff79aa0  r14:00000000000046de  r15:0000000000000000
     es:0000  cs:0033  ss:002b  ds:0000  fs:0000  gs:0000
[002b:00007ffe10fbffe8]---------------------------------------------------------[stack]
00007ffe10fbffe8 : 5d 07 40 00  00 00 00 00 - 48 9a f7 cf  5f 7f 00 00 ].@.....H..._...
00007ffe10fbfff8 : 86 05 40 00  00 00 00 00 - 00 00 00 00  00 00 00 00 ..@.............
00007ffe10fc0008 : 22 a6 f2 cf  5f 7f 00 00 - 00 00 00 00  00 00 00 00 "..._...........
00007ffe10fc0018 : 00 00 00 00  00 00 00 00 - 7e 3c b0 20  00 00 00 00 ........~<. ....
[0000:0000000000400000]---------------------------------------------------------[ data]
0000000000400000 : 7f 45 4c 46  02 01 01 00 - 00 00 00 00  00 00 00 00 .ELF............
0000000000400010 : 02 00 3e 00  01 00 00 00 - 00 06 40 00  00 00 00 00 ..>.......@.....
[0033:00000000004005c0]---------------------------------------------------------[ code]
> 00000000004005c0: jmp qword [rel 0x402010]
  00000000004005c6: push 2
  00000000004005cb: jmp 0x400590
  00000000004005d0: jmp qword [rel 0x402018]
  00000000004005d6: push 3
  00000000004005db: jmp 0x400590
------------------------------------------------------------------------------

It's about to jump to 0x402010, which is inside the rw- memory range (not the r-x range) for conftest-2.

That section of memory:

00000000:00402010|00 00 00 00 00 00 00 00 38 9e f1 cf 5f 7f 00 00|........8..._...|

Attempting to execute this instruction gives the following state:

------------------------------------------------------------------------------
     rax:00000000004005c0 rcx:0000000000000000  rdx:0000000000400580  rbx:00007f5fcff798c0     rflags:0000000000000206
     rsp:00007ffe10fbffe8 rbp:00007ffe10fbfff0  rsi:0000000000402060  rdi:0000000000400818        rip:0000000000000000
      r8:0000000000400801  r9:0000000000000000  r10:00007f5fcff61ae0  r11:00007f5fcff79b60           o d I t s z a P c
     r12:000000000040076d r13:00007f5fcff79aa0  r14:00000000000046de  r15:0000000000000000
     es:0000  cs:0033  ss:002b  ds:0000  fs:0000  gs:0000
[002b:00007ffe10fbffe8]---------------------------------------------------------[stack]
00007ffe10fbffe8 : 5d 07 40 00  00 00 00 00 - 48 9a f7 cf  5f 7f 00 00 ].@.....H..._...
00007ffe10fbfff8 : 86 05 40 00  00 00 00 00 - 00 00 00 00  00 00 00 00 ..@.............
00007ffe10fc0008 : 22 a6 f2 cf  5f 7f 00 00 - 00 00 00 00  00 00 00 00 "..._...........
00007ffe10fc0018 : 00 00 00 00  00 00 00 00 - 7e 3c b0 20  00 00 00 00 ........~<. ....
[0000:0000000000402010]---------------------------------------------------------[ data]
0000000000402010 : 00 00 00 00  00 00 00 00 - 38 9e f1 cf  5f 7f 00 00 ........8..._...
0000000000402020 : 68 93 f1 cf  5f 7f 00 00 - a0 92 f1 cf  5f 7f 00 00 h..._......._...
[0033:0000000000000000]---------------------------------------------------------[ code]
------------------------------------------------------------------------------

And stepping once more segmentation faults.

@bb010g
Copy link

bb010g commented May 21, 2020

NixOS/nixpkgs#49071 might be our issue here?

@bb010g
Copy link

bb010g commented May 21, 2020

After chasing issues down, it looks like NixOS/nixpkgs#84741 fixed this problem, and applying NixOS/nixpkgs@acfccf7 to nixos-20.03 lets GHC build properly.

@bb010g
Copy link

bb010g commented May 22, 2020

Cloning Aura & running nix-build ./nix -A staticProject.static_package will give you a successful static build using nixos-20.03, Stack 2.1, and Stackage lts-15.13. Not sure how to go about upstreaming all the patches in there to make those play. (At least the Nixpkgs patch shouldn't be necessary on nixos-unstable (as the merged commit, NixOS/nixpkgs@4675649, is present.)

Gabriella439 added a commit to dhall-lang/dhall-haskell that referenced this issue Aug 16, 2020
This is a revamp of our use of
[fully static Haskell executables](NixOS/nixpkgs#43795).
The main changes are:

* We can now use a newer revision of Nixpkgs

  The current revision we're using corresponds to Nixpkgs 20.03

* We can now more easily update Nixpkgs

  The logic in this repository more closely tracks how `static-haskell-nix`
  works, so whenever that repository updates Nixpkgs we can pick up the change
  here, too.

  Note that we cannot currently use Nixpkgs `master` due to
  [this issue](NixOS/nixpkgs#85924), but once that is
  fixed when we can track Nixpkgs `master` more freely.

* We no longer need to keep track of separate Nixpkgs revisions for
  static vs. non-static builds

  The two builds can also share dependencies, too.  Only the top-level
  derivations differ now.

The reason that this doesn't use `static-haskell-nix` directly is because of
[`cabal2nix` evaluation failures](nh2/static-haskell-nix#73),
so this change works by lifting just the minimum logic that we need from
the `static-haskell-nix` repository until we can finally use that
repository (or Nixpkgs directly when it's upstreamed).
Gabriella439 added a commit to dhall-lang/dhall-haskell that referenced this issue Aug 22, 2020
This is a revamp of our use of
[fully static Haskell executables](NixOS/nixpkgs#43795).
The main changes are:

* We can now use a newer revision of Nixpkgs

  The current revision we're using corresponds to Nixpkgs 20.03

* We can now more easily update Nixpkgs

  The logic in this repository more closely tracks how `static-haskell-nix`
  works, so whenever that repository updates Nixpkgs we can pick up the change
  here, too.

  Note that we cannot currently use Nixpkgs `master` due to
  [this issue](NixOS/nixpkgs#85924), but once that is
  fixed when we can track Nixpkgs `master` more freely.

* We no longer need to keep track of separate Nixpkgs revisions for
  static vs. non-static builds

  The two builds can also share dependencies, too.  Only the top-level
  derivations differ now.

The reason that this doesn't use `static-haskell-nix` directly is because of
[`cabal2nix` evaluation failures](nh2/static-haskell-nix#73),
so this change works by lifting just the minimum logic that we need from
the `static-haskell-nix` repository until we can finally use that
repository (or Nixpkgs directly when it's upstreamed).
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

No branches or pull requests

5 participants