haskellPackages: Add buildFromCabalSdist (faster, tested)

+94
+3
pkgs/development/haskell-modules/lib/compose.nix
··· 299 299 directly. The effect is that the package is built as if it were published 300 300 on hackage. This can be used as a test for the source distribution, 301 301 assuming the build fails when packaging mistakes are in the cabal file. 302 + 303 + A faster implementation using `cabal-install` is available as 304 + `buildFromCabalSdist` in your Haskell package set. 302 305 */ 303 306 buildFromSdist = pkg: overrideCabal (drv: { 304 307 src = "${sdistTarball pkg}/${pkg.pname}-${pkg.version}.tar.gz";
+40
pkgs/development/haskell-modules/make-package-set.nix
··· 538 538 withHoogle = self.ghcWithHoogle; 539 539 }; 540 540 541 + /* 542 + Run `cabal sdist` on a source. 543 + 544 + Unlike `haskell.lib.sdistTarball`, this does not require any dependencies 545 + to be present, as it uses `cabal-install` instead of building `Setup.hs`. 546 + This makes `cabalSdist` faster than `sdistTarball`. 547 + */ 548 + cabalSdist = { 549 + src, 550 + name ? if src?name then "${src.name}-sdist.tar.gz" else "source.tar.gz" 551 + }: 552 + pkgs.runCommandNoCCLocal name 553 + { 554 + inherit src; 555 + nativeBuildInputs = [ buildHaskellPackages.cabal-install ]; 556 + dontUnpack = false; 557 + } '' 558 + unpackPhase 559 + cd "''${sourceRoot:-.}" 560 + patchPhase 561 + mkdir out 562 + HOME=$PWD cabal sdist --output-directory out 563 + mv out/*.tar.gz $out 564 + ''; 565 + 566 + /* 567 + Like `haskell.lib.buildFromSdist`, but using `cabal sdist` instead of 568 + building `./Setup`. 569 + 570 + Unlike `haskell.lib.buildFromSdist`, this does not require any dependencies 571 + to be present. This makes `buildFromCabalSdist` faster than `haskell.lib.buildFromSdist`. 572 + */ 573 + buildFromCabalSdist = pkg: 574 + haskellLib.overrideSrc 575 + { 576 + src = self.cabalSdist { inherit (pkg) src; }; 577 + version = pkg.version; 578 + } 579 + pkg; 580 + 541 581 }
+28
pkgs/test/haskell/cabalSdist/default.nix
··· 1 + { lib, haskellPackages, runCommand }: 2 + 3 + let 4 + localRaw = haskellPackages.callCabal2nix "local" ./local {}; 5 + in 6 + lib.recurseIntoAttrs rec { 7 + 8 + helloFromCabalSdist = haskellPackages.buildFromCabalSdist haskellPackages.hello; 9 + 10 + # A more complicated example with a cabal hook. 11 + hercules-ci-cnix-store = haskellPackages.buildFromCabalSdist haskellPackages.hercules-ci-cnix-store; 12 + 13 + localFromCabalSdist = haskellPackages.buildFromCabalSdist localRaw; 14 + 15 + assumptionLocalHasDirectReference = runCommand "localHasDirectReference" { 16 + drvPath = builtins.unsafeDiscardOutputDependency localRaw.drvPath; 17 + } '' 18 + grep ${./local} $drvPath >/dev/null 19 + touch $out 20 + ''; 21 + 22 + localHasNoDirectReference = runCommand "localHasNoDirectReference" { 23 + drvPath = builtins.unsafeDiscardOutputDependency localFromCabalSdist.drvPath; 24 + } '' 25 + grep -v ${./local} $drvPath >/dev/null 26 + touch $out 27 + ''; 28 + }
+5
pkgs/test/haskell/cabalSdist/local/CHANGELOG.md
··· 1 + # Revision history for local 2 + 3 + ## 0.1.0.0 -- YYYY-mm-dd 4 + 5 + * First version. Released on an unsuspecting world.
+4
pkgs/test/haskell/cabalSdist/local/app/Main.hs
··· 1 + module Main where 2 + 3 + main :: IO () 4 + main = putStrLn "Hello, Haskell!"
+13
pkgs/test/haskell/cabalSdist/local/local.cabal
··· 1 + cabal-version: 2.4 2 + name: local 3 + version: 0.1.0.0 4 + 5 + synopsis: Nixpkgs test case 6 + license: MIT 7 + extra-source-files: CHANGELOG.md 8 + 9 + executable local 10 + main-is: Main.hs 11 + build-depends: base 12 + hs-source-dirs: app 13 + default-language: Haskell2010
+1
pkgs/test/haskell/default.nix
··· 2 2 3 3 lib.recurseIntoAttrs { 4 4 shellFor = callPackage ./shellFor { }; 5 + cabalSdist = callPackage ./cabalSdist { }; 5 6 documentationTarball = callPackage ./documentationTarball { }; 6 7 setBuildTarget = callPackage ./setBuildTarget { }; 7 8 writers = callPackage ./writers { };