mirror of
https://github.com/nmattia/snack.git
synced 2024-12-01 11:15:54 +03:00
60 lines
1.5 KiB
Nix
60 lines
1.5 KiB
Nix
|
{ 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
|
||
|
);
|
||
|
}
|