1
1
mirror of https://github.com/nmattia/snack.git synced 2024-12-01 11:15:54 +03:00
snack/snack-lib/package-spec.nix

60 lines
1.5 KiB
Nix
Raw Normal View History

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 ? []
, packages ? lib.filter (x: builtins.typeOf x != "string") dependencies
}:
{ packageMain = main;
packageBase = src;
packageGhcOpts = ghcOpts;
packageDependencies = lib.filter (x: builtins.typeOf x == "string") dependencies;
# TODO: merge extra files and extra dirs together
packageExtraFiles =
if builtins.isList extra-files
then (_x: extra-files)
else extra-files;
packageExtraDirectories =
if builtins.isList extra-directories
then (_x: extra-directories)
else extra-directories;
packagePackages = map mkPackageSpec packages;
};
flattenPackages = topPkgSpec:
[topPkgSpec] ++ lib.lists.concatMap (flattenPackages) topPkgSpec.packagePackages;
# TODO: nub
allTransitiveDeps = topPkgSpec:
lib.lists.concatMap
(pkgSpec: pkgSpec.packageDependencies)
(flattenPackages topPkgSpec);
# Returns the first package spec that contains a module with given name. If
# none is found, returns the supplied default value.
pkgSpecByModuleName = pkgs: def: modName:
( lib.findFirst
(pkgSpec:
lib.lists.elem
modName
(listModulesInDir pkgSpec.packageBase)
)
def
pkgs
);
}