haskellPackages.buildFromCabalSdist: add test, fix double-patch

srcOnly applies patches, but the resulting derivation still had the
patches attribute, causing patchPhase to apply them again. Clear
patches after srcOnly to prevent double-application.
This commit is contained in:
Robert Hensing
2025-12-28 15:26:33 +01:00
parent 3692288912
commit 5a38e15e6d
3 changed files with 37 additions and 4 deletions
@@ -695,10 +695,18 @@ package-set { inherit pkgs lib callPackage; } self
*/
buildFromCabalSdist =
pkg:
haskellLib.overrideSrc {
src = self.cabalSdist { src = pkgs.srcOnly pkg; };
version = pkg.version;
} pkg;
haskellLib.overrideCabal
(_: {
# Patches are already applied by srcOnly above, so clear them
# to avoid double-application.
patches = [ ];
})
(
haskellLib.overrideSrc {
src = self.cabalSdist { src = pkgs.srcOnly pkg; };
version = pkg.version;
} pkg
);
/*
Modify a Haskell package to add shell completion scripts for the
@@ -0,0 +1,8 @@
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -1,4 +1,4 @@
module Main where
main :: IO ()
-main = putStrLn "Hello, Haskell!"
+main = putStrLn "Hello, Patched Haskell!"
+17
View File
@@ -7,6 +7,9 @@
let
localRaw = haskellPackages.callPackage ./generated.nix { };
# A patched variant to test that buildFromCabalSdist respects patches
localPatched = haskell.lib.appendPatches localRaw [ ./change-greeting.patch ];
in
lib.recurseIntoAttrs rec {
@@ -40,4 +43,18 @@ lib.recurseIntoAttrs rec {
grep -v ${localRaw.src} $drvPath >/dev/null
touch $out
'';
# Test that buildFromCabalSdist respects patches applied to the package.
# The patch changes the greeting from "Hello, Haskell!" to "Hello, Patched Haskell!".
localPatchedFromCabalSdist = haskellPackages.buildFromCabalSdist localPatched;
patchRespected =
runCommand "patchRespected"
{
nativeBuildInputs = [ localPatchedFromCabalSdist ];
}
''
${lib.getExe localPatchedFromCabalSdist} | grep "Patched" >/dev/null
touch $out
'';
}