From 705561e32e624b94343512d0b9de5cddd72fa9fa Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 2 Dec 2026 15:16:24 +0000 Subject: 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. --- pkgs/haskell/default.nix | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'pkgs/haskell/default.nix') 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); }; } -- cgit v1.3.1