Skip to content

Commit

Permalink
implement multiple package dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
HariAmoor-professional committed Oct 16, 2022
1 parent c584317 commit 4a39868
Showing 1 changed file with 58 additions and 2 deletions.
60 changes: 58 additions & 2 deletions flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,32 @@ in
};
};
};
topLevelPackages = mkOption {
type = types.submodule {
options = {
enableMultiPkgs = mkBoolOption {
description = "Whether or not to use multiple top-level package dirs";
default = false;
};

dirs = mkOption {
type = types.listOf types.str;
description = ''
Subdirs containing a separate Cabal package
Define as nonempty only if enableMultiPkgs is set to `true`
'';
default = [ ];
};

defaultPkg = mkOption {
type = types.str;
description = "Default package to pass to flake if multiple packages exist";
default = "";
};
};
};
};
};
});
};
Expand Down Expand Up @@ -151,6 +177,23 @@ in
(pkgs.lib.composeExtensions
(pkgs.haskell.lib.packageSourceOverrides cfg.source-overrides)
cfg.overrides);
hp = hp.extend
(
let
enableMultiPkgs = cfg.topLevelPackages.enableMultiPkgs;
dirs = cfg.topLevelPackages.dirs;
in
if enableMultiPkgs then
(self: _:
listToAttrs (map
(dir: {
name = dir;
value = self.callCabal2nix dir ./${dir} { };
})
dirs)
)
else (_: _: { })
);
defaultBuildTools = hp: with hp; {
inherit
cabal-install
Expand All @@ -159,9 +202,22 @@ in
hlint;
};
buildTools = lib.attrValues (defaultBuildTools hp // cfg.buildTools hp);
package = cfg.modifier (hp.callCabal2nixWithOptions cfg.name cfg.root "" { });
package =
if cfg.topLevelPackages.enableMultiPkgs then
hp.${cfg.topLevelPackages.defaultPkg}
else
cfg.modifier (hp.callCabal2nixWithOptions cfg.name cfg.root "" { });
devShell = with pkgs.haskell.lib;
(addBuildTools package buildTools).envFunc { withHoogle = true; };
(addBuildTools package buildTools).envFunc (
{
withHoogle = true;
} // (
if cfg.topLevelPackages.enableMultiPkgs then {
packages = pkgs: map (pkg: pkgs.${pkg}) cfg.topLevelPackages.dirs;
buildInputs = [ hp.ghcid ];
} else { }
)
);
devShellCheck = name: command:
runCommandInSimulatedShell devShell cfg.root "${projectKey}-${name}-check" { } command;
in
Expand Down

0 comments on commit 4a39868

Please sign in to comment.