summaryrefslogtreecommitdiffstats
path: root/pkgs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-12-02 15:16:24 +0000
committertv <tv@krebsco.de>2026-12-02 18:02:30 +0000
commit705561e32e624b94343512d0b9de5cddd72fa9fa (patch)
tree23c1d68bfd73ac1474c0edeb6a072cb1fbbd8f00 /pkgs
parent460a470aceda32eec69207fa4ab9fc67c5fc0397 (diff)
pkgs/haskell: an automatic package from the checkout's cabal.nix
If the checkout has one, instead of running cabal2nix during evaluation. It starts with the sha256 of the .cabal file it was made from, and a mismatch fails evaluation, with the command that makes it again.
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/haskell/default.nix19
1 files changed, 18 insertions, 1 deletions
diff --git a/pkgs/haskell/default.nix b/pkgs/haskell/default.nix
index 68b79b8c..73c917e4 100644
--- a/pkgs/haskell/default.nix
+++ b/pkgs/haskell/default.nix
@@ -21,6 +21,23 @@ self: super: let
inherit name src;
removeNames = [ ".git" ".graveyard" "dist-newstyle" ];
};
+
+ # An automatic package, from the checkout's cabal.nix if it has one,
+ # else from cabal2nix run during evaluation. cabal.nix starts with
+ # the sha256 of the .cabal file it was made from, and fails evaluation
+ # when that changed.
+ automaticPackage = hself: pname: dir: let
+ src = cleanHaskellSource pname dir;
+ stored = dir + "/cabal.nix";
+ header = "# cabal-sha256: ${builtins.hashFile "sha256" (dir + "/${pname}.cabal")}";
+ regenerate = ''{ printf '%s\n' '${header}'; cabal2nix .; } > cabal.nix'';
+ in
+ if !builtins.pathExists stored then
+ hself.callCabal2nix pname src {}
+ else if builtins.head (lib.splitString "\n" (builtins.readFile stored)) != header then
+ throw "pkgs/haskell: ${toString stored} is stale against ${pname}.cabal; in ${toString dir}, run: ${regenerate}"
+ else
+ self.haskell.lib.overrideSrc (hself.callPackage stored {}) { inherit src; };
in {
# nixpkgs applies packageOverrides to every Haskell package set, including
# haskellPackages.
@@ -29,6 +46,6 @@ in {
(hself: hsuper:
mylib.mapNixDir (path: hself.callPackage path {}) [ ./. ]
//
- lib.mapAttrs (pname: src: hself.callCabal2nix pname (cleanHaskellSource pname src) {}) automaticPackages);
+ lib.mapAttrs (automaticPackage hself) automaticPackages);
};
}