diff options
author | Robert Hensing <roberth@users.noreply.github.com> | 2022-06-28 10:06:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-28 10:06:27 +0200 |
commit | d64780ea0e22b5f61cd6012a456869c702a72f20 (patch) | |
tree | 4b47ae60684a279ee949f84a7d76c640dc54f376 | |
parent | fc6cea3c6cff75ae7152758995986d7279bc175a (diff) | |
parent | 392fba113292aa10ba8ea9b68710a73ca17cac0e (diff) | |
download | nixpkgs-d64780ea0e22b5f61cd6012a456869c702a72f20.tar nixpkgs-d64780ea0e22b5f61cd6012a456869c702a72f20.tar.gz nixpkgs-d64780ea0e22b5f61cd6012a456869c702a72f20.tar.bz2 nixpkgs-d64780ea0e22b5f61cd6012a456869c702a72f20.tar.lz nixpkgs-d64780ea0e22b5f61cd6012a456869c702a72f20.tar.xz nixpkgs-d64780ea0e22b5f61cd6012a456869c702a72f20.tar.zst nixpkgs-d64780ea0e22b5f61cd6012a456869c702a72f20.zip |
Merge pull request #174176 from hercules-ci/buildFromCabalSdist
haskellPackages: Add buildFromCabalSdist (faster, tested)
-rw-r--r-- | pkgs/development/haskell-modules/lib/compose.nix | 3 | ||||
-rw-r--r-- | pkgs/development/haskell-modules/make-package-set.nix | 40 | ||||
-rw-r--r-- | pkgs/test/haskell/cabalSdist/default.nix | 28 | ||||
-rw-r--r-- | pkgs/test/haskell/cabalSdist/local/CHANGELOG.md | 5 | ||||
-rw-r--r-- | pkgs/test/haskell/cabalSdist/local/app/Main.hs | 4 | ||||
-rw-r--r-- | pkgs/test/haskell/cabalSdist/local/generated.nix | 12 | ||||
-rw-r--r-- | pkgs/test/haskell/cabalSdist/local/local.cabal | 13 | ||||
-rw-r--r-- | pkgs/test/haskell/default.nix | 1 |
8 files changed, 106 insertions, 0 deletions
diff --git a/pkgs/development/haskell-modules/lib/compose.nix b/pkgs/development/haskell-modules/lib/compose.nix index 600bf80cb19..4c11a4e1e8b 100644 --- a/pkgs/development/haskell-modules/lib/compose.nix +++ b/pkgs/development/haskell-modules/lib/compose.nix @@ -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"; diff --git a/pkgs/development/haskell-modules/make-package-set.nix b/pkgs/development/haskell-modules/make-package-set.nix index 80dc94af4df..579f6a350b0 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 00000000000..1031e51e4f1 --- /dev/null +++ b/pkgs/test/haskell/cabalSdist/default.nix @@ -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 + ''; +} diff --git a/pkgs/test/haskell/cabalSdist/local/CHANGELOG.md b/pkgs/test/haskell/cabalSdist/local/CHANGELOG.md new file mode 100644 index 00000000000..53cc3ae43d8 --- /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 00000000000..65ae4a05d5d --- /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/generated.nix b/pkgs/test/haskell/cabalSdist/local/generated.nix new file mode 100644 index 00000000000..bfa299962bc --- /dev/null +++ b/pkgs/test/haskell/cabalSdist/local/generated.nix @@ -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; +} diff --git a/pkgs/test/haskell/cabalSdist/local/local.cabal b/pkgs/test/haskell/cabalSdist/local/local.cabal new file mode 100644 index 00000000000..1670aa3af63 --- /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 03e4f346155..337d2811c65 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 { }; |