diff --git a/pkgs/development/haskell-modules/lib/compose.nix b/pkgs/development/haskell-modules/lib/compose.nix index a831a83a15f5..bdd1c6766f55 100644 --- a/pkgs/development/haskell-modules/lib/compose.nix +++ b/pkgs/development/haskell-modules/lib/compose.nix @@ -299,6 +299,9 @@ rec { directly. The effect is that the package is built as if it were published on hackage. This can be used as a test for the source distribution, assuming the build fails when packaging mistakes are in the cabal file. + + A faster implementation using `cabal-install` is available as + `buildFromCabalSdist` in your Haskell package set. */ buildFromSdist = pkg: overrideCabal (drv: { src = "${sdistTarball pkg}/${pkg.pname}-${pkg.version}.tar.gz"; diff --git a/pkgs/development/haskell-modules/make-package-set.nix b/pkgs/development/haskell-modules/make-package-set.nix index 80dc94af4df6..579f6a350b04 100644 --- a/pkgs/development/haskell-modules/make-package-set.nix +++ b/pkgs/development/haskell-modules/make-package-set.nix @@ -538,4 +538,44 @@ in package-set { inherit pkgs lib callPackage; } self // { withHoogle = self.ghcWithHoogle; }; + /* + Run `cabal sdist` on a source. + + Unlike `haskell.lib.sdistTarball`, this does not require any dependencies + to be present, as it uses `cabal-install` instead of building `Setup.hs`. + This makes `cabalSdist` faster than `sdistTarball`. + */ + cabalSdist = { + src, + name ? if src?name then "${src.name}-sdist.tar.gz" else "source.tar.gz" + }: + pkgs.runCommandNoCCLocal name + { + inherit src; + nativeBuildInputs = [ buildHaskellPackages.cabal-install ]; + dontUnpack = false; + } '' + unpackPhase + cd "''${sourceRoot:-.}" + patchPhase + mkdir out + HOME=$PWD cabal sdist --output-directory out + mv out/*.tar.gz $out + ''; + + /* + Like `haskell.lib.buildFromSdist`, but using `cabal sdist` instead of + building `./Setup`. + + Unlike `haskell.lib.buildFromSdist`, this does not require any dependencies + to be present. This makes `buildFromCabalSdist` faster than `haskell.lib.buildFromSdist`. + */ + buildFromCabalSdist = pkg: + haskellLib.overrideSrc + { + src = self.cabalSdist { inherit (pkg) src; }; + version = pkg.version; + } + pkg; + } diff --git a/pkgs/test/haskell/cabalSdist/default.nix b/pkgs/test/haskell/cabalSdist/default.nix new file mode 100644 index 000000000000..2ab815f5d4f6 --- /dev/null +++ b/pkgs/test/haskell/cabalSdist/default.nix @@ -0,0 +1,28 @@ +{ lib, haskellPackages, runCommand }: + +let + localRaw = haskellPackages.callCabal2nix "local" ./local {}; +in +lib.recurseIntoAttrs rec { + + helloFromCabalSdist = haskellPackages.buildFromCabalSdist haskellPackages.hello; + + # A more complicated example with a cabal hook. + hercules-ci-cnix-store = haskellPackages.buildFromCabalSdist haskellPackages.hercules-ci-cnix-store; + + localFromCabalSdist = haskellPackages.buildFromCabalSdist localRaw; + + assumptionLocalHasDirectReference = runCommand "localHasDirectReference" { + drvPath = builtins.unsafeDiscardOutputDependency localRaw.drvPath; + } '' + grep ${./local} $drvPath >/dev/null + touch $out + ''; + + localHasNoDirectReference = runCommand "localHasNoDirectReference" { + drvPath = builtins.unsafeDiscardOutputDependency localFromCabalSdist.drvPath; + } '' + grep -v ${./local} $drvPath >/dev/null + touch $out + ''; +} diff --git a/pkgs/test/haskell/cabalSdist/local/CHANGELOG.md b/pkgs/test/haskell/cabalSdist/local/CHANGELOG.md new file mode 100644 index 000000000000..53cc3ae43d8a --- /dev/null +++ b/pkgs/test/haskell/cabalSdist/local/CHANGELOG.md @@ -0,0 +1,5 @@ +# Revision history for local + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/pkgs/test/haskell/cabalSdist/local/app/Main.hs b/pkgs/test/haskell/cabalSdist/local/app/Main.hs new file mode 100644 index 000000000000..65ae4a05d5db --- /dev/null +++ b/pkgs/test/haskell/cabalSdist/local/app/Main.hs @@ -0,0 +1,4 @@ +module Main where + +main :: IO () +main = putStrLn "Hello, Haskell!" diff --git a/pkgs/test/haskell/cabalSdist/local/local.cabal b/pkgs/test/haskell/cabalSdist/local/local.cabal new file mode 100644 index 000000000000..1670aa3af631 --- /dev/null +++ b/pkgs/test/haskell/cabalSdist/local/local.cabal @@ -0,0 +1,13 @@ +cabal-version: 2.4 +name: local +version: 0.1.0.0 + +synopsis: Nixpkgs test case +license: MIT +extra-source-files: CHANGELOG.md + +executable local + main-is: Main.hs + build-depends: base + hs-source-dirs: app + default-language: Haskell2010 diff --git a/pkgs/test/haskell/default.nix b/pkgs/test/haskell/default.nix index 03e4f3461558..337d2811c655 100644 --- a/pkgs/test/haskell/default.nix +++ b/pkgs/test/haskell/default.nix @@ -2,6 +2,7 @@ lib.recurseIntoAttrs { shellFor = callPackage ./shellFor { }; + cabalSdist = callPackage ./cabalSdist { }; documentationTarball = callPackage ./documentationTarball { }; setBuildTarget = callPackage ./setBuildTarget { }; writers = callPackage ./writers { };