Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cabal2nix integration for IFD-less evalutation #382

Merged
merged 10 commits into from
Dec 23, 2024
31 changes: 29 additions & 2 deletions nix/build-haskell-package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ let
name = "${name}";
inherit src;
};

callPackageKeepDeriver = src: args:
srid marked this conversation as resolved.
Show resolved Hide resolved
pkgs.haskell.lib.compose.overrideCabal
(orig: {
inherit src; # Override original source path to use new
passthru = orig.passthru or { } // {
# When using cabal2nix, it is often useful
# to debug a failure by inspecting the Nix expression
# generated by cabal2nix. This can be accessed via this
# cabal2nixDeriver field.
cabal2nixDeriver = src;
};
})
(self.callPackage src args);
in

name: root:
Expand All @@ -31,6 +45,19 @@ lib.pipe root
(mkNewStorePath "source-${name}")
(x: log.traceDebug "${name}.mkNewStorePath ${x.outPath}" x)

(root: self.callCabal2nix name root { })
(x: log.traceDebug "${name}.cabal2nixDeriver ${x.cabal2nixDeriver.outPath}" x)
(root:
# Check if cached cabal2nix generated nix expression is present,
# if present use it with callPackage
# to avoid IFD
let pkg =
if lib.pathExists (lib.concatStringsSep "/" [ root "default.nix" ])
srid marked this conversation as resolved.
Show resolved Hide resolved
then
(log.traceDebug "${name}.callPackageKeepDeriver ${root}")
callPackageKeepDeriver root { }
else
(log.traceDebug "${name}.callCabal2nix ${root}")
self.callCabal2nix name root { };
in
(log.traceDebug "${name}.cabal2nixDeriver ${pkg.cabal2nixDeriver.outPath}" pkg)
)
]
3 changes: 1 addition & 2 deletions nix/modules/project/packages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ in
getOrMkPackage = name: cfg:
if lib.types.path.check cfg.source
then
log.traceDebug "${name}.callCabal2nix ${cfg.source}"
(build-haskell-package name cfg.source)
(build-haskell-package name cfg.source)
else
log.traceDebug "${name}.callHackage ${cfg.source}"
(self.callHackage name cfg.source { });
Expand Down