diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88ced05..1a21a61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,10 @@ jobs: steps: - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v31 + with: + nix_path: nixpkgs=channel:nixpkgs-unstable + - run: nix-channel --update - name: Install ArrayFire run: brew install arrayfire @@ -33,6 +37,15 @@ jobs: - name: Configure run: cabal configure --flags="disable-default-paths disable-build-tool-depends" --extra-include-dirs=$(brew --prefix arrayfire)/include --extra-lib-dirs=$(brew --prefix arrayfire)/lib - - name: Build - run: cabal build arrayfire + - name: hspec-discover + run: nix-shell -p ghc -p cabal-install --keep LD_LIBRARY_PATH --run 'cabal install hspec-discover' + - name: Build + run: nix-shell -p ghc -p cabal-install --keep LD_LIBRARY_PATH --run 'cabal build' + env: + LD_LIBRARY_PATH: "/opt/arrayfire/lib:/opt/arrayfire/lib64" + + - name: Nix build + run: nix build + env: + LD_LIBRARY_PATH: "/opt/arrayfire/lib:/opt/arrayfire/lib64" diff --git a/flake.lock b/flake.lock index 27da0e5..c767330 100644 --- a/flake.lock +++ b/flake.lock @@ -1,28 +1,5 @@ { "nodes": { - "arrayfire-nix": { - "inputs": { - "flake-utils": [ - "flake-utils" - ], - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1692793973, - "narHash": "sha256-6dG41ile3T+6dfRazlcPBdKBarGesswsBpb40Lcf35U=", - "owner": "twesterhout", - "repo": "arrayfire-nix", - "rev": "4236770612b80a3f29adbd8d670f6cea2bc098ba", - "type": "github" - }, - "original": { - "owner": "twesterhout", - "repo": "arrayfire-nix", - "type": "github" - } - }, "flake-utils": { "inputs": { "systems": "systems" @@ -74,7 +51,6 @@ }, "root": { "inputs": { - "arrayfire-nix": "arrayfire-nix", "flake-utils": "flake-utils", "nix-filter": "nix-filter", "nixpkgs": "nixpkgs" diff --git a/flake.nix b/flake.nix index d7f0af7..c79dea1 100644 --- a/flake.nix +++ b/flake.nix @@ -5,11 +5,6 @@ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; nix-filter.url = "github:numtide/nix-filter"; - arrayfire-nix = { - url = "github:twesterhout/arrayfire-nix"; - inputs.flake-utils.follows = "flake-utils"; - inputs.nixpkgs.follows = "nixpkgs"; - }; }; outputs = inputs: @@ -30,13 +25,47 @@ ]; }; + # Build ArrayFire from the official binary installer; avoids freeimage entirely. + mkArrayfire = pkgs: pkgs.stdenv.mkDerivation rec { + pname = "arrayfire"; + version = "3.10.0"; + src = pkgs.fetchurl { + url = "https://arrayfire.s3.amazonaws.com/${version}/ArrayFire-v${version}_Linux_x86_64.sh"; + hash = "sha256-8SibCWnRxts79S6WEHb3skF2TIDl1QnjY6EiohmoIog="; + }; + nativeBuildInputs = [ pkgs.autoPatchelfHook ]; + buildInputs = with pkgs; [ + stdenv.cc.cc.lib + fftw + fftwFloat + openblas + ocl-icd + boost.out + ]; + unpackPhase = "true"; + installPhase = '' + mkdir -p $out + bash $src --exclude-subdir --prefix=$out + ''; + meta = { + description = "A general-purpose library for parallel and massively-parallel architectures"; + platforms = [ "x86_64-linux" ]; + }; + }; + + arrayfire-overlay = self: super: { + arrayfire = mkArrayfire self; + }; + # An overlay that lets us test arrayfire-haskell with different GHC versions arrayfire-haskell-overlay = self: super: { haskell = super.haskell // { packageOverrides = inputs.nixpkgs.lib.composeExtensions super.haskell.packageOverrides (hself: hsuper: { arrayfire = self.haskell.lib.appendConfigureFlags - (hself.callCabal2nix "arrayfire" src { af = self.arrayfire; }) + (hself.callCabal2nix "arrayfire" src { + af = self.arrayfire; + }) [ "-f disable-default-paths" ]; }); }; @@ -56,8 +85,6 @@ doctest hsc2hs hspec-discover - # Language servers - haskell-language-server nil # Formatters nixpkgs-fmt @@ -69,7 +96,7 @@ pkgs-for = system: import inputs.nixpkgs { inherit system; overlays = [ - inputs.arrayfire-nix.overlays.default + arrayfire-overlay arrayfire-haskell-overlay ]; }; @@ -78,7 +105,6 @@ packages = inputs.flake-utils.lib.eachDefaultSystemMap (system: with (pkgs-for system); { default = haskellPackages.arrayfire; - haskell = haskell.packages; }); devShells = inputs.flake-utils.lib.eachDefaultSystemMap (system: {