2018-06-16 19:09:16 +03:00
|
|
|
{ lib
|
|
|
|
, singleOut
|
|
|
|
, callPackage
|
|
|
|
}:
|
|
|
|
|
|
|
|
with (callPackage ./modules.nix { inherit singleOut; });
|
|
|
|
|
|
|
|
rec {
|
|
|
|
|
|
|
|
mkPackageSpec =
|
|
|
|
packageDescr@
|
|
|
|
{ src
|
|
|
|
, main ? null
|
|
|
|
, ghcOpts ? []
|
|
|
|
, dependencies ? []
|
|
|
|
, extra-files ? []
|
|
|
|
, extra-directories ? []
|
2018-06-22 17:14:10 +03:00
|
|
|
, packages ? []
|
2018-06-16 19:09:16 +03:00
|
|
|
}:
|
|
|
|
{ packageMain = main;
|
|
|
|
packageBase = src;
|
|
|
|
packageGhcOpts = ghcOpts;
|
2018-06-22 17:59:24 +03:00
|
|
|
packageDependencies = mkPerModuleAttr dependencies;
|
2018-06-16 19:09:16 +03:00
|
|
|
|
|
|
|
# TODO: merge extra files and extra dirs together
|
2018-06-22 17:59:24 +03:00
|
|
|
packageExtraFiles = mkPerModuleAttr extra-files;
|
|
|
|
packageExtraDirectories = mkPerModuleAttr extra-directories;
|
2018-06-16 19:09:16 +03:00
|
|
|
packagePackages = map mkPackageSpec packages;
|
|
|
|
};
|
|
|
|
|
2018-06-22 17:59:24 +03:00
|
|
|
mkPerModuleAttr = attr:
|
|
|
|
if builtins.isList attr
|
|
|
|
then (_: attr)
|
|
|
|
else if builtins.isAttrs attr
|
|
|
|
then (x: attr.${x})
|
|
|
|
else if builtins.isFunction attr
|
|
|
|
then attr
|
|
|
|
else
|
|
|
|
abort "Unknown type for per module attributes: ${builtins.typeOf attr}";
|
|
|
|
|
2018-06-16 19:09:16 +03:00
|
|
|
flattenPackages = topPkgSpec:
|
|
|
|
[topPkgSpec] ++ lib.lists.concatMap (flattenPackages) topPkgSpec.packagePackages;
|
|
|
|
|
2018-06-17 16:54:57 +03:00
|
|
|
# Traverses all transitive packages and returns the first package spec that
|
|
|
|
# contains a module with given name. If none is found, returns the supplied
|
|
|
|
# default value.
|
|
|
|
pkgSpecByModuleName = topPkgSpec: def: modName:
|
2018-06-16 19:09:16 +03:00
|
|
|
( lib.findFirst
|
|
|
|
(pkgSpec:
|
|
|
|
lib.lists.elem
|
|
|
|
modName
|
|
|
|
(listModulesInDir pkgSpec.packageBase)
|
|
|
|
)
|
|
|
|
def
|
2018-06-17 16:54:57 +03:00
|
|
|
(flattenPackages topPkgSpec)
|
2018-06-16 19:09:16 +03:00
|
|
|
);
|
|
|
|
}
|