6 # Within the package components, these are the attribute names of
16 foldrAttrVals = f: z: attrs:
17 lib.foldr (g: acc: g acc) z (lib.mapAttrsToList (_name: f) attrs);
19 foldComponents = tys: f: z: conf:
21 comps = conf.components or {};
22 # ensure that comps.library exists and is not null.
23 libComp = acc: if (comps.library or null) != null then f comps.library acc else acc;
26 (ty: acc': foldrAttrVals f acc' (comps.${ty} or {}))
29 in libComp (subComps z);
31 getAllComponents = foldComponents subComponentTypes (c: acc:
32 lib.optional c.buildable c ++ acc) [];
35 # Are all of these right?
37 foreignlibs = "foreignlib";
43 applyComponents = f: config:
45 comps = config.components;
46 applyLibrary = cname: f { cname = config.package.identifier.name; ctype = "lib"; };
47 applySubComp = ctype: cname: f { inherit cname; ctype = componentPrefix.${ctype} or (throw "Missing component mapping for ${ctype}."); };
48 applyAllComp = f { cname = config.package.identifier.name; ctype = "all"; };
49 buildableAttrs = lib.filterAttrs (n: comp: comp.buildable or true);
50 libComp = if comps.library == null || !(comps.library.buildable or true)
52 else lib.mapAttrs applyLibrary (removeAttrs comps (subComponentTypes ++ [ "all" ]));
53 subComps = lib.mapAttrs
54 (ctype: attrs: lib.mapAttrs (applySubComp ctype) (buildableAttrs attrs))
55 (builtins.intersectAttrs (lib.genAttrs subComponentTypes (_: null)) comps);
56 allComp = { all = applyAllComp comps.all; };
57 in subComps // libComp // allComp;
59 isLibrary = componentId: componentId.ctype == "lib";
60 isAll = componentId: componentId.ctype == "all";
61 isTest = componentId: componentId.ctype == "test";
62 isBenchmark = componentId: componentId.ctype == "bench";
64 # Was there a reference to the package source in the `cabal.project` or `stack.yaml` file.
65 # This is used to make the default `packages` list for `shellFor`.
66 isLocalPackage = p: p.isLocal or false;
67 selectLocalPackages = ps: lib.filterAttrs (n: p: p != null && isLocalPackage p) ps;
69 # Format a componentId as it should appear as a target on the
70 # command line of the setup script.
71 componentTarget = componentId:
72 if componentId.ctype == "all" then ""
73 else "${componentId.ctype}:${componentId.cname}";
75 # Remove null or empty values from an attrset.
76 optionalHooks = lib.filterAttrs (_: hook: hook != null && hook != "");
78 # Avoid pkgs.callPackage for now. It does a lot of nonsense with OOP
79 # style programming that we should avoid until we know we want it.
81 # weakCallPackage: call a function or (importable expression)
84 # weakCallPackage scope f args
85 # will call f (scope // args)
87 # weakCallpackage scope ./path args
88 # will call the expression at ./path with (scope // args)
90 weakCallPackage = scope: f: args:
91 let f' = if lib.isFunction f then f else import f;
92 args' = (builtins.intersectAttrs (builtins.functionArgs f') scope) // args;
95 # Collect all (transitive) Haskell library dependencies of a
97 ## flatLibDepends :: Component -> [Package]
98 flatLibDepends = component:
100 makePairs = map (p: rec { key="${val}"; val=(p.components.library or p); });
101 closure = builtins.genericClosure {
102 startSet = makePairs component.depends;
103 operator = {val,...}: makePairs val.config.depends;
105 in map ({val,...}: val) closure;
107 # Extracts a selection of components from a Haskell package set.
109 # This can be used to filter out all test suites or benchmarks of
110 # your project, so that they can be built in Hydra.
114 # tests = collectComponents "tests" (package: package.identifier.name == "mypackage") hsPkgs;
116 # Will result in moving:
117 # from: hsPkgs.mypackage.components.tests.unit-tests
118 # to: tests.mypackage.unit-tests
120 collectComponents = group: packageSel: haskellPackages:
121 (mapAttrs (_: package: package.components.${group} // { recurseForDerivations = true; })
122 (filterAttrs (name: package: (package.isHaskell or false) && packageSel package) haskellPackages))
123 // { recurseForDerivations = true; };
125 # Replacement for lib.cleanSourceWith that has a subDir argument.
126 inherit (import ./clean-source-with.nix { inherit lib; }) cleanSourceWith canCleanSource;
128 # Use cleanSourceWith to filter just the files needed for a particular
129 # component of a package
130 cleanCabalComponent = import ./clean-cabal-component.nix { inherit lib cleanSourceWith; };
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list