mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-28 14:22:50 +03:00
Merge pull request #174176 from hercules-ci/buildFromCabalSdist
haskellPackages: Add buildFromCabalSdist (faster, tested)
This commit is contained in:
commit
d64780ea0e
@ -300,6 +300,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";
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
28
pkgs/test/haskell/cabalSdist/default.nix
Normal file
28
pkgs/test/haskell/cabalSdist/default.nix
Normal file
@ -0,0 +1,28 @@
|
||||
{ lib, haskellPackages, runCommand }:
|
||||
|
||||
let
|
||||
localRaw = haskellPackages.callPackage ./local/generated.nix {};
|
||||
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
|
||||
'';
|
||||
}
|
5
pkgs/test/haskell/cabalSdist/local/CHANGELOG.md
Normal file
5
pkgs/test/haskell/cabalSdist/local/CHANGELOG.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Revision history for local
|
||||
|
||||
## 0.1.0.0 -- YYYY-mm-dd
|
||||
|
||||
* First version. Released on an unsuspecting world.
|
4
pkgs/test/haskell/cabalSdist/local/app/Main.hs
Normal file
4
pkgs/test/haskell/cabalSdist/local/app/Main.hs
Normal file
@ -0,0 +1,4 @@
|
||||
module Main where
|
||||
|
||||
main :: IO ()
|
||||
main = putStrLn "Hello, Haskell!"
|
12
pkgs/test/haskell/cabalSdist/local/generated.nix
Normal file
12
pkgs/test/haskell/cabalSdist/local/generated.nix
Normal file
@ -0,0 +1,12 @@
|
||||
# nix run ../../../../..#cabal2nix -- ./.
|
||||
{ mkDerivation, base, lib }:
|
||||
mkDerivation {
|
||||
pname = "local";
|
||||
version = "0.1.0.0";
|
||||
src = ./.;
|
||||
isLibrary = false;
|
||||
isExecutable = true;
|
||||
executableHaskellDepends = [ base ];
|
||||
description = "Nixpkgs test case";
|
||||
license = lib.licenses.mit;
|
||||
}
|
13
pkgs/test/haskell/cabalSdist/local/local.cabal
Normal file
13
pkgs/test/haskell/cabalSdist/local/local.cabal
Normal file
@ -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
|
@ -2,6 +2,7 @@
|
||||
|
||||
lib.recurseIntoAttrs {
|
||||
shellFor = callPackage ./shellFor { };
|
||||
cabalSdist = callPackage ./cabalSdist { };
|
||||
documentationTarball = callPackage ./documentationTarball { };
|
||||
setBuildTarget = callPackage ./setBuildTarget { };
|
||||
writers = callPackage ./writers { };
|
||||
|
Loading…
Reference in New Issue
Block a user