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
28 changes: 25 additions & 3 deletions nix/build-haskell-package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,37 @@ let
name = "${name}";
inherit src;
};

in

name: root:
name: root: cabal2NixFile:
lib.pipe root
[
# Avoid rebuilding because of changes in parent directories
(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:
let path = "${root}/${cabal2NixFile}";
in
# Check if cached cabal2nix generated nix expression is present,
# if present use it with callPackage
# to avoid IFD
if builtins.pathExists path
then
(log.traceDebug "${name}.callPackage[cabal2nix] ${path}")
self.callPackage
path
{ }
else
let
pkg =
(log.traceDebug "${name}.callCabal2nix ${root}")
self.callCabal2nix
name
root
{ };
in
(log.traceDebug "${name}.cabal2nixDeriver ${pkg.cabal2nixDeriver.outPath}" pkg)
srid marked this conversation as resolved.
Show resolved Hide resolved
srid marked this conversation as resolved.
Show resolved Hide resolved
)
]
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 cfg.cabal2NixFile)
else
log.traceDebug "${name}.callHackage ${cfg.source}"
(self.callHackage name cfg.source { });
Expand Down
10 changes: 10 additions & 0 deletions nix/modules/project/packages/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ in
'';
};

cabal2NixFile = lib.mkOption {
type = lib.types.str;
description = ''
The Nix file which contains cached (pre-generated) `cabal2nix` expressions.

By default, it refers to `cabal.nix` file.
'';
default = "cabal.nix";
};

cabal.executables = mkOption {
type = types.nullOr (types.listOf types.str);
description = ''
Expand Down