NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
16.66k stars 13.11k forks source link

Haskell Cabal Flags Being Ignored? #33926

Closed idontgetoutmuch closed 6 years ago

idontgetoutmuch commented 6 years ago

Issue description

nix-build fails with a cabal configure error

Steps to reproduce

nix-build --attr project1 release1.nix

release1.nix:

let
config = {
  packageOverrides = pkgs: rec {
    haskellPackages = pkgs.haskellPackages.override {
      overrides = haskellPackagesNew: haskellPackagesOld: rec {
        project1 =
          haskellPackagesNew.callPackage ./default.nix { };
        hmatrix =
          pkgs.haskell.lib.enableCabalFlag (pkgs.haskell.lib.enableCabalFlag (haskellPackagesNew.callPackage ./hmatrix.nix { }) "openblas") "disable-default-paths";
      };
    };
  };
};

pkgs = import <nixpkgs> { inherit config; };

in
{ project1 = pkgs.haskellPackages.project1;
}

default.nix:

{ mkDerivation, base, stdenv, hmatrix }:
mkDerivation {
  pname = "project1";
  version = "1.0.0";
  src = ./.;
  isLibrary = false;
  isExecutable = true;
  executableHaskellDepends = [ base hmatrix ];
  license = stdenv.lib.licenses.bsd3;
}

hmatrix.nix:

{ mkDerivation, array, base, binary, openblas, bytestring, deepseq
, liblapack, random, semigroups, split, stdenv, storable-complex
, vector
}:
mkDerivation {
  pname = "hmatrix";
  version = "0.18.1.1";
  src = /Users/dom/hmatrix/packages/base;
  libraryHaskellDepends = [
    array base binary bytestring deepseq random semigroups split
    storable-complex vector
  ];
  librarySystemDepends = [ openblas liblapack ];
  preConfigure = "sed -i hmatrix.cabal -e '/\\/usr\\//D'";
  homepage = "https://github.com/albertoruiz/hmatrix";
  description = "Numeric Linear Algebra";
  license = stdenv.lib.licenses.bsd3;
}

hmatrix.cabal:

Name:               hmatrix
Version:            0.18.1.1
License:            BSD3
License-file:       LICENSE
Author:             Alberto Ruiz
Maintainer:         Alberto Ruiz
Stability:          provisional
Homepage:           https://github.com/albertoruiz/hmatrix
Synopsis:           Numeric Linear Algebra
Description:        Linear systems, matrix decompositions, and other numerical computations based on BLAS and LAPACK.
                    .
                    Standard interface: "Numeric.LinearAlgebra".
                    .
                    Safer interface with statically checked dimensions: "Numeric.LinearAlgebra.Static".
                    .
                    Code examples: <http://dis.um.es/~alberto/hmatrix/hmatrix.html>

Category:           Math
tested-with:        GHC==8.0

cabal-version:      >=1.8

build-type:         Simple

extra-source-files: THANKS.md CHANGELOG

extra-source-files: src/Internal/C/lapack-aux.h

flag openblas
    description:    Link with OpenBLAS (https://github.com/xianyi/OpenBLAS) optimized libraries.
    default:        False
    manual: True

flag disable-default-paths
    description:    When enabled, don't add default hardcoded include/link dirs by default. Needed for hermetic builds like in nix.
    default:        False
    manual: True

library

    Build-Depends:      base >= 4.8 && < 5,
                        binary,
                        array,
                        deepseq,
                        random,
                        split,
                        bytestring,
                        storable-complex,
                        semigroups,
                        vector >= 0.8

    hs-source-dirs:     src

    exposed-modules:    Numeric.LinearAlgebra
                        Numeric.LinearAlgebra.Devel
                        Numeric.LinearAlgebra.Data
                        Numeric.LinearAlgebra.HMatrix
                        Numeric.LinearAlgebra.Static

    other-modules:      Internal.Vector
                        Internal.Devel
                        Internal.Vectorized
                        Internal.Matrix
                        Internal.ST
                        Internal.IO
                        Internal.Element
                        Internal.Conversion
                        Internal.LAPACK
                        Internal.Numeric
                        Internal.Algorithms
                        Internal.Random
                        Internal.Container
                        Internal.Sparse
                        Internal.Convolution
                        Internal.Chain
                        Numeric.Vector
                        Internal.CG
                        Numeric.Matrix
                        Internal.Util
                        Internal.Modular
                        Internal.Static

    C-sources:          src/Internal/C/lapack-aux.c
                        src/Internal/C/vector-aux.c

    extensions:         ForeignFunctionInterface

    ghc-options:        -Wall
                        -fno-warn-missing-signatures
                        -fno-warn-orphans
                        -fno-prof-auto

    cc-options:         -O4 -Wall

    if arch(x86_64)
        cc-options:     -msse2
    if arch(i386)
        cc-options:     -msse2

    if os(OSX)
        if flag(openblas)
            if !flag(disable-default-paths)
                extra-lib-dirs:     /opt/local/lib/openblas/lib
            extra-libraries:    openblas
        else
            extra-libraries:    blas lapack

        if !flag(disable-default-paths)
            extra-lib-dirs: /opt/local/lib/
            include-dirs: /opt/local/include/
            extra-lib-dirs: /usr/local/lib/
            include-dirs: /usr/local/include/
        if arch(i386)
            cc-options: -arch i386
        frameworks: Accelerate

    if os(freebsd)
        if flag(openblas)
            if !flag(disable-default-paths)
                extra-lib-dirs:     /usr/local/lib/openblas/lib
            extra-libraries:    openblas
        else
            extra-libraries:    blas lapack

        if !flag(disable-default-paths)
            extra-lib-dirs: /usr/local/lib
            include-dirs: /usr/local/include
        extra-libraries: gfortran

    if os(windows)
        if flag(openblas)
            extra-libraries:    libopenblas, libgcc_s_seh-1, libgfortran, libquadmath-0
        else
            extra-libraries:    blas lapack

    if os(linux)
        if flag(openblas)
            if !flag(disable-default-paths)
                extra-lib-dirs:     /usr/lib/openblas/lib
            extra-libraries:    openblas
        else
            extra-libraries:    blas lapack

        if arch(x86_64)
            cc-options: -fPIC

source-repository head
    type:     git
    location: https://github.com/albertoruiz/hmatrix

The failure is

bash-3.2$ nix-build --attr project1 release1.nix
these derivations will be built:
  /nix/store/kwbz470cnc3bg1zyhq6ckyg88hlygap1-hmatrix-0.18.1.1.drv
  /nix/store/zhfabzxnmq5b230d46h34f7vikxmsh9y-project1-1.0.0.drv
building path(s) ‘/nix/store/qxvvaq4niags06vlj9w2di9k3abi44y5-hmatrix-0.18.1.1-doc’, ‘/nix/store/vkm582lmmd1mhf09qgv7i60jrsp3xljr-hmatrix-0.18.1.1’
setupCompilerEnvironmentPhase
Build with /nix/store/2szhjd6206nmvl0fakkadai4jwfcdycc-ghc-8.0.2.
unpacking sources
unpacking source archive /nix/store/6q2zp3wcqwhh4zx0pav8f6dx919cc425-base
source root is base
patching sources
compileBuildDriverPhase
setupCompileFlags: -package-db=/private/tmp/nix-build-hmatrix-0.18.1.1.drv-0/package.conf.d -j1 -threaded
[1 of 1] Compiling Main             ( Setup.lhs, /private/tmp/nix-build-hmatrix-0.18.1.1.drv-0/Main.o )
Linking Setup ...
configuring
configureFlags: --verbose --prefix=/nix/store/vkm582lmmd1mhf09qgv7i60jrsp3xljr-hmatrix-0.18.1.1 --libdir=$prefix/lib/$compiler --libsubdir=$pkgid --docdir=/nix/store/qxvvaq4niags06vlj9w2di9k3abi44y5-hmatrix-0.18.1.1-doc/share/doc --with-gcc=clang --package-db=/private/tmp/nix-build-hmatrix-0.18.1.1.drv-0/package.conf.d --ghc-option=-optl=-Wl,-headerpad_max_install_names --ghc-option=-j1 --disable-split-objs --disable-library-profiling --disable-profiling --enable-shared --disable-coverage --enable-library-vanilla --enable-executable-dynamic --enable-tests -fopenblas -fdisable-default-paths --extra-include-dirs=/nix/store/3mj5i7xqii2kd3dpx9avkxmyhnig9zv7-openblas-0.2.20/include --extra-lib-dirs=/nix/store/3mj5i7xqii2kd3dpx9avkxmyhnig9zv7-openblas-0.2.20/lib --extra-lib-dirs=/nix/store/bgbhyzfx5yilan9qydnzyxybd71am6dz-liblapack-3.4.1/lib --extra-include-dirs=/nix/store/vgbc1jcn639f4nrrszxyaagxx0frss2a-atlas-3.10.2/include --extra-lib-dirs=/nix/store/vgbc1jcn639f4nrrszxyaagxx0frss2a-atlas-3.10.2/lib --extra-include-dirs=/nix/store/cfl3g7nakfffmk3a9g8frjbj74wfayra-libc++-4.0.1/include --extra-lib-dirs=/nix/store/cfl3g7nakfffmk3a9g8frjbj74wfayra-libc++-4.0.1/lib
Setup: hmatrix.cabal:119: 'then' branch of 'if' is empty
builder for ‘/nix/store/kwbz470cnc3bg1zyhq6ckyg88hlygap1-hmatrix-0.18.1.1.drv’ failed with exit code 1
cannot build derivation ‘/nix/store/zhfabzxnmq5b230d46h34f7vikxmsh9y-project1-1.0.0.drv’: 1 dependencies couldn't be built
error: build of ‘/nix/store/zhfabzxnmq5b230d46h34f7vikxmsh9y-project1-1.0.0.drv’ failed`

Here is the relevant line:

https://github.com/albertoruiz/hmatrix/blob/master/packages/base/hmatrix.cabal#L119

Technical details

Please run nix-shell -p nix-info --run "nix-info -m" and paste the results.

bash-3.2$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-darwin"`
 - host os: `Darwin 17.3.0, macOS 10.13.2`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 1.11.15`
 - channels(root): `"nixpkgs-18.03pre122117.14df60d0db9"`
 - channels(dom): `""`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`
idontgetoutmuch commented 6 years ago

nix generates a cabal configure command (see above). If I run this at the CLI

cabal configure 
--verbose 
--prefix=/nix/store/xjkd9wwym237wbza28hr8mysq9rp0cp3-hmatrix-0.18.1.1 
--libdir=$prefix/lib/$compiler 
--libsubdir=$pkgid 
--docdir=/nix/store/nhkhx3aa32bk8dpilf3g7mhrpa9y1jmq-hmatrix-0.18.1.1-doc/share/doc 
--with-gcc=clang 
--package-db=/private/tmp/nix-build-hmatrix-0.18.1.1.drv-0/package.conf.d 
--ghc-option=-optl=-Wl,-headerpad_max_install_names 
--ghc-option=-j1 
--disable-split-objs 
--disable-library-profiling 
--disable-profiling 
--enable-shared 
--disable-coverage 
--enable-library-vanilla 
--enable-executable-dynamic 
--enable-tests -fopenblas -fdisable-default-paths
--extra-include-dirs=/nix/store/3mj5i7xqii2kd3dpx9avkxmyhnig9zv7-openblas-0.2.20/include 
--extra-lib-dirs=/nix/store/3mj5i7xqii2kd3dpx9avkxmyhnig9zv7-openblas-0.2.20/lib 
--extra-lib-dirs=/nix/store/bgbhyzfx5yilan9qydnzyxybd71am6dz-liblapack-3.4.1/lib 
--extra-include-dirs=/nix/store/vgbc1jcn639f4nrrszxyaagxx0frss2a-atlas-3.10.2/include 
--extra-lib-dirs=/nix/store/vgbc1jcn639f4nrrszxyaagxx0frss2a-atlas-3.10.2/lib 
--extra-include-dirs=/nix/store/cfl3g7nakfffmk3a9g8frjbj74wfayra-libc++-4.0.1/include
--extra-lib-dirs=/nix/store/cfl3g7nakfffmk3a9g8frjbj74wfayra-libc++-4.0.1/lib

then this step succeeds

Using a sandbox located at /Users/dom/hmatrix/packages/base/.cabal-sandbox
/Users/dom/.nix-profile/bin/ghc --numeric-version
looking for tool ghc-pkg near compiler in /Users/dom/.nix-profile/bin
found ghc-pkg in /Users/dom/.nix-profile/bin/ghc-pkg
/Users/dom/.nix-profile/bin/ghc-pkg --version
/Users/dom/.nix-profile/bin/ghc --supported-languages
/Users/dom/.nix-profile/bin/ghc --info
Reading available packages...
index-state(hackage.haskell.org) = 2018-01-09T20:11:22Z
index-state() =
/Users/dom/.nix-profile/bin/pkg-config --version
/Users/dom/.nix-profile/bin/pkg-config --list-all
/Users/dom/.nix-profile/bin/pkg-config --modversion
Failed to query pkg-config, Cabal will continue without solving for pkg-config
constraints: dieVerbatim: user error (CallStack (from HasCallStack):
die', called at ./Distribution/Simple/Program/Run.hs:171:7 in
Cabal-2.0.1.1-AinAwvgvuAO6LrBWWFTAd2:Distribution.Simple.Program.Run
getProgramInvocationOutput, called at ./Distribution/Simple/Program.hs:165:3
in Cabal-2.0.1.1-AinAwvgvuAO6LrBWWFTAd2:Distribution.Simple.Program
getProgramOutput, called at ./Distribution/Solver/Types/PkgConfigDb.hs:70:28
in main:Distribution.Solver.Types.PkgConfigDb
cabal: '/Users/dom/.nix-profile/bin/pkg-config' exited with an error:
Must specify package names on the command line
)
Resolving dependencies...
Using internal setup method with build-type Simple and args:
["configure","--verbose=2","--ghc","--prefix=/nix/store/xjkd9wwym237wbza28hr8mysq9rp0cp3-hmatrix-0.18.1.1","--bindir=$prefix/bin","--libdir=/lib/","--libsubdir=","--dynlibdir=$libdir/$abi","--libexecdir=$prefix/libexec","--libexecsubdir=$abi/$pkgid","--datadir=$prefix/share","--datasubdir=$abi/$pkgid","--docdir=/nix/store/nhkhx3aa32bk8dpilf3g7mhrpa9y1jmq-hmatrix-0.18.1.1-doc/share/doc","--htmldir=$docdir/html","--haddockdir=$htmldir","--sysconfdir=$prefix/etc","--enable-library-vanilla","--disable-library-profiling","--enable-shared","--enable-executable-dynamic","--disable-profiling","--disable-split-objs","--global","--package-db=/Users/dom/hmatrix/packages/base/.cabal-sandbox/x86_64-osx-ghc-8.0.2-packages.conf.d","--flags=openblas","--flags=disable-default-paths","--extra-include-dirs=/nix/store/3mj5i7xqii2kd3dpx9avkxmyhnig9zv7-openblas-0.2.20/include","--extra-include-dirs=/nix/store/vgbc1jcn639f4nrrszxyaagxx0frss2a-atlas-3.10.2/include","--extra-include-dirs=/nix/store/cfl3g7nakfffmk3a9g8frjbj74wfayra-libc++-4.0.1/include","--ipid=hmatrix-0.18.1.1-D06BQIMqMCsIs1bt9tbOUn","--extra-lib-dirs=/nix/store/3mj5i7xqii2kd3dpx9avkxmyhnig9zv7-openblas-0.2.20/lib","--extra-lib-dirs=/nix/store/bgbhyzfx5yilan9qydnzyxybd71am6dz-liblapack-3.4.1/lib","--extra-lib-dirs=/nix/store/vgbc1jcn639f4nrrszxyaagxx0frss2a-atlas-3.10.2/lib","--extra-lib-dirs=/nix/store/cfl3g7nakfffmk3a9g8frjbj74wfayra-libc++-4.0.1/lib","--extra-prog-path=/Users/dom/.cabal/bin","--dependency=array=array-0.5.1.1","--dependency=base=base-4.9.1.0","--dependency=binary=binary-0.8.3.0","--dependency=bytestring=bytestring-0.10.8.1","--dependency=deepseq=deepseq-1.4.2.0","--dependency=random=random-1.1-9tceXaeYIMZ4JrKq20Egog","--dependency=semigroups=semigroups-0.18.3-IxQNmCA7qrSEQNkoHSF7A","--dependency=split=split-0.2.3.2-CJl40zTyCIV16Pr60nb7CT","--dependency=storable-complex=storable-complex-0.2.2-68P661PjpFUQpfwmdxcda","--dependency=vector=vector-0.12.0.1-BtK5bVORdhu8bC6gqUfFYi","--enable-tests","--disable-coverage","--exact-configuration","--disable-benchmarks","--with-gcc=clang","--ghc-option=-optl=-Wl,-headerpad_max_install_names","--ghc-option=-j1"]
Configuring hmatrix-0.18.1.1...
Flags chosen: disable-default-paths=True, openblas=True
Dependency array ==0.5.1.1: using array-0.5.1.1
Dependency base ==4.9.1.0: using base-4.9.1.0
Dependency binary ==0.8.3.0: using binary-0.8.3.0
Dependency bytestring ==0.10.8.1: using bytestring-0.10.8.1
Dependency deepseq ==1.4.2.0: using deepseq-1.4.2.0
Dependency random ==1.1: using random-1.1
Dependency semigroups ==0.18.3: using semigroups-0.18.3
Dependency split ==0.2.3.2: using split-0.2.3.2
Dependency storable-complex ==0.2.2: using storable-complex-0.2.2
Dependency vector ==0.12.0.1: using vector-0.12.0.1
Source component graph: component lib
Configured component graph:
    component hmatrix-0.18.1.1-D06BQIMqMCsIs1bt9tbOUn
        include base-4.9.1.0
        include binary-0.8.3.0
        include array-0.5.1.1
        include deepseq-1.4.2.0
        include random-1.1-9tceXaeYIMZ4JrKq20Egog
        include split-0.2.3.2-CJl40zTyCIV16Pr60nb7CT
        include bytestring-0.10.8.1
        include storable-complex-0.2.2-68P661PjpFUQpfwmdxcda
        include semigroups-0.18.3-IxQNmCA7qrSEQNkoHSF7A
        include vector-0.12.0.1-BtK5bVORdhu8bC6gqUfFYi
Linked component graph:
    unit hmatrix-0.18.1.1-D06BQIMqMCsIs1bt9tbOUn
        include base-4.9.1.0
        include binary-0.8.3.0
        include array-0.5.1.1
        include deepseq-1.4.2.0
        include random-1.1-9tceXaeYIMZ4JrKq20Egog
        include split-0.2.3.2-CJl40zTyCIV16Pr60nb7CT
        include bytestring-0.10.8.1
        include storable-complex-0.2.2-68P661PjpFUQpfwmdxcda
        include semigroups-0.18.3-IxQNmCA7qrSEQNkoHSF7A
        include vector-0.12.0.1-BtK5bVORdhu8bC6gqUfFYi
        Numeric.LinearAlgebra=hmatrix-0.18.1.1-D06BQIMqMCsIs1bt9tbOUn:Numeric.LinearAlgebra,Numeric.LinearAlgebra.Data=hmatrix-0.18.1.1-D06BQIMqMCsIs1bt9tbOUn:Numeric.LinearAlgebra.Data,Numeric.LinearAlgebra.Devel=hmatrix-0.18.1.1-D06BQIMqMCsIs1bt9tbOUn:Numeric.LinearAlgebra.Devel,Numeric.LinearAlgebra.HMatrix=hmatrix-0.18.1.1-D06BQIMqMCsIs1bt9tbOUn:Numeric.LinearAlgebra.HMatrix,Numeric.LinearAlgebra.Static=hmatrix-0.18.1.1-D06BQIMqMCsIs1bt9tbOUn:Numeric.LinearAlgebra.Static
Ready component graph:
    definite hmatrix-0.18.1.1-D06BQIMqMCsIs1bt9tbOUn
        depends base-4.9.1.0
        depends binary-0.8.3.0
        depends array-0.5.1.1
        depends deepseq-1.4.2.0
        depends random-1.1-9tceXaeYIMZ4JrKq20Egog
        depends split-0.2.3.2-CJl40zTyCIV16Pr60nb7CT
        depends bytestring-0.10.8.1
        depends storable-complex-0.2.2-68P661PjpFUQpfwmdxcda
        depends semigroups-0.18.3-IxQNmCA7qrSEQNkoHSF7A
        depends vector-0.12.0.1-BtK5bVORdhu8bC6gqUfFYi
Using Cabal-2.0.1.1 compiled by ghc-8.0
Using compiler: ghc-8.0.2
Using install prefix:
/nix/store/xjkd9wwym237wbza28hr8mysq9rp0cp3-hmatrix-0.18.1.1
Executables installed in:
/nix/store/xjkd9wwym237wbza28hr8mysq9rp0cp3-hmatrix-0.18.1.1/bin
Libraries installed in: /lib/
Dynamic Libraries installed in: /lib//x86_64-osx-ghc-8.0.2
Private executables installed in:
/nix/store/xjkd9wwym237wbza28hr8mysq9rp0cp3-hmatrix-0.18.1.1/libexec/x86_64-osx-ghc-8.0.2/hmatrix-0.18.1.1
Data files installed in:
/nix/store/xjkd9wwym237wbza28hr8mysq9rp0cp3-hmatrix-0.18.1.1/share/x86_64-osx-ghc-8.0.2/hmatrix-0.18.1.1
Documentation installed in:
/nix/store/nhkhx3aa32bk8dpilf3g7mhrpa9y1jmq-hmatrix-0.18.1.1-doc/share/doc
Configuration files installed in:
/nix/store/xjkd9wwym237wbza28hr8mysq9rp0cp3-hmatrix-0.18.1.1/etc
No alex found
Using ar found on system at:
/nix/store/lb93fgb9hm5ispds27rp34zb1j24v9v8-cctools-binutils-darwin/bin/ar
No c2hs found
No cpphs found
No doctest found
Using gcc version 4.2.1 given by user at: /usr/bin/clang
Using ghc version 8.0.2 found on system at: /Users/dom/.nix-profile/bin/ghc
Using ghc-pkg version 8.0.2 found on system at:
/Users/dom/.nix-profile/bin/ghc-pkg
No ghcjs found
No ghcjs-pkg found
No greencard found
Using haddock version 2.17.3 found on system at:
/Users/dom/.nix-profile/bin/haddock
No happy found
Using haskell-suite found on system at: haskell-suite-dummy-location
Using haskell-suite-pkg found on system at: haskell-suite-pkg-dummy-location
No hmake found
Using hpc version 0.67 found on system at: /Users/dom/.nix-profile/bin/hpc
Using hsc2hs version 0.68.1 found on system at:
/Users/dom/.nix-profile/bin/hsc2hs
No hscolour found
No jhc found
Using ld found on system at:
/nix/store/p1fm10d3hr68nrjddq7zr38zax5pgjax-clang-wrapper-4.0.1/bin/ld
No lhc found
No lhc-pkg found
Using pkg-config version 0.29.2 found on system at:
/Users/dom/.nix-profile/bin/pkg-config
Using runghc version 8.0.2 found on system at:
/Users/dom/.nix-profile/bin/runghc
Using strip found on system at: /usr/bin/strip
Using tar found on system at: /usr/bin/tar
No uhc found

NB that the flags are set correctly: Flags chosen: disable-default-paths=True, openblas=True

mpickering commented 6 years ago

Seems like this is happening because of the preConfigure options for hmatrix.

       preConfigure = "sed -i hmatrix.cabal -e '/\\/usr\\//D'";   
idontgetoutmuch commented 6 years ago

I have created my own nix file using cabal2nix and then commenting out the offending line. Specifically I have

        hmatrix =
          pkgs.haskell.lib.enableCabalFlag (pkgs.haskell.lib.enableCabalFlag (haskellPackagesNew.callPackage ./hmatrix.nix { }) "openblas") "disable-default-paths";

and

{ mkDerivation, array, base, binary, openblas, bytestring, deepseq
, liblapack, random, semigroups, split, stdenv, storable-complex
, vector
}:
mkDerivation {
  pname = "hmatrix";
  version = "0.18.1.1";
  src = /Users/dom/hmatrix/packages/base;
  libraryHaskellDepends = [
    array base binary bytestring deepseq random semigroups split
    storable-complex vector
  ];
  librarySystemDepends = [ openblas liblapack ];
  # preConfigure = "sed -i hmatrix.cabal -e '/\\/usr\\//D'";
  homepage = "https://github.com/albertoruiz/hmatrix";
  description = "Numeric Linear Algebra";
  license = stdenv.lib.licenses.bsd3;
}
idontgetoutmuch commented 6 years ago

Now it compiles but linking fails:

[27 of 27] Compiling Numeric.LinearAlgebra.HMatrix ( src/Numeric/LinearAlgebra/HMatrix.hs, dist/build/Numeric/LinearAlgebra/HMatrix.o )
ld: framework not found Accelerate
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)
`cc' failed in phase `Linker'. (Exit code: 1)
note: keeping build directory ‘/private/tmp/nix-build-hmatrix-0.18.1.1.drv-41’
builder for ‘/nix/store/nxjafarxcbkhkbzc272fhihqlh7m3cs2-hmatrix-0.18.1.1.drv’ failed with exit code 1
cannot build derivation ‘/nix/store/jb22nf039plngnc8w107nay0zzpl5hdx-project1-1.0.0.drv’: 1 dependencies couldn't be built
error: build of ‘/nix/store/jb22nf039plngnc8w107nay0zzpl5hdx-project1-1.0.0.drv’ failed
mpickering commented 6 years ago

You are missing the override found in configuration-nix.nix.

  hmatrix = if pkgs.stdenv.isDarwin                                             
    then addBuildDepend super.hmatrix pkgs.darwin.apple_sdk.frameworks.Accelerate
    else super.hmatrix; 
idontgetoutmuch commented 6 years ago
{ mkDerivation, array, base, binary, openblas, bytestring, deepseq
, random, semigroups, split, stdenv, storable-complex
, vector
, fetchFromGitHub
, darwin
}:
let
  src = fetchFromGitHub {
    owner = "albertoruiz";
    repo = "hmatrix";
    rev = "0d4018b09f1d38bbc05fdc0d8197d0f8a6ce5571";
    sha256 = "0l6pvgkrykjkdi3q71qh7b2fk5alnf9qr9fi80dwj9xyaqpiwn3l";
  };
in
mkDerivation {
  pname = "hmatrix";
  version = "0.18.1.1";
  src = "${src}/packages/base";
  buildDepends = [ (stdenv.lib.optionals stdenv.isDarwin darwin.apple_sdk.frameworks.Accelerate) ];
  configureFlags = [
    "-fdisable-default-paths"
    "-fopenblas"
  ];
  libraryHaskellDepends = [
    array base binary bytestring deepseq random semigroups split
    storable-complex vector
  ];
  librarySystemDepends = [ openblas ];
  # preConfigure = "sed -i hmatrix.cabal -e '/\\/usr\\//D'";
  homepage = "https://github.com/albertoruiz/hmatrix";
  description = "Numeric Linear Algebra";
  license = stdenv.lib.licenses.bsd3;
}

# I have many questions:
#
# 1. I would like to use the blas that comes with OSX but if I replace
# openblas by blas, this derivation(?) picks up the Haskell package
# called blas not the nix package called blas
#
# bash-3.2$ nix-env -qaPf /Users/dom/nixpkgs |
# grep -i blas
#
# blas                                                   blas-3.7.1
#
# bash-3.2$ nix-env -f /Users/dom/nixpkgs -qaP -A haskellPackages |
#           grep -i blas
#
# haskellPackages.blas                                         blas-0.7.6
idontgetoutmuch commented 6 years ago

@copumpkin comments

copumpkin> no 5:34 PM optionals takes a list and returns a list 5:34 PM which means that you're not passing it what it expects, and it'll do weird stuff if we get stricter about types 5:34 PM plus shouldn't it be buildInputs? 5:34 PM lib.optional will take a single value and wrap it in a list or return an empty list 5:35 PM lib.optionals takes a list and return it or return an empty list

idontgetoutmuch commented 6 years ago

5:34 PM plus shouldn't it be buildInputs? no because the haskellPackages.mkDerivation is changing all of the things compared to the stdenv.mkDerivation, while keeping the same name

mpickering commented 6 years ago

I think this an be closed now?

idontgetoutmuch commented 6 years ago

I think so. See also https://github.com/albertoruiz/hmatrix/pull/219, https://github.com/albertoruiz/hmatrix/issues/243 and https://github.com/NixOS/cabal2nix/commit/08768660b1e4e4104153007728b1fe5c55122657.