summaryrefslogtreecommitdiffstats
path: root/pkgs/haskell/default.nix
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
commit4a066f2e12c58484a850dc8e0b7b0f47f4a70ebd (patch)
tree6245f2d43ccad04db5289eb1bd37185fe6aed8e5 /pkgs/haskell/default.nix
parent83125fa856951466ed45dfe6b6f417a37dd7e5da (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/haskell/default.nix')
-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);
};
}
[cgit] Unable to lock slot /tmp/cgit/56200000.lock: Permission denied (13)