Merge pull request #51884 from alyssais/bundlerEnv-groups
bundlerEnv: improve handling of groups
This commit is contained in:
commit
b450083ee3
@ -94,6 +94,15 @@ rec {
|
|||||||
attrValues = builtins.attrValues or (attrs: attrVals (attrNames attrs) attrs);
|
attrValues = builtins.attrValues or (attrs: attrVals (attrNames attrs) attrs);
|
||||||
|
|
||||||
|
|
||||||
|
/* Given a set of attribute names, return the set of the corresponding
|
||||||
|
attributes from the given set.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
getAttrs [ "a" "b" ] { a = 1; b = 2; c = 3; }
|
||||||
|
=> { a = 1; b = 2; }
|
||||||
|
*/
|
||||||
|
getAttrs = names: attrs: genAttrs names (name: attrs.${name});
|
||||||
|
|
||||||
/* Collect each attribute named `attr' from a list of attribute
|
/* Collect each attribute named `attr' from a list of attribute
|
||||||
sets. Sets that don't contain the named attribute are ignored.
|
sets. Sets that don't contain the named attribute are ignored.
|
||||||
|
|
||||||
|
@ -61,10 +61,10 @@ let
|
|||||||
boolToString mergeAttrs flip mapNullable inNixShell min max
|
boolToString mergeAttrs flip mapNullable inNixShell min max
|
||||||
importJSON warn info nixpkgsVersion version mod compare
|
importJSON warn info nixpkgsVersion version mod compare
|
||||||
splitByAndCompare functionArgs setFunctionArgs isFunction;
|
splitByAndCompare functionArgs setFunctionArgs isFunction;
|
||||||
inherit (fixedPoints) fix fix' extends composeExtensions
|
inherit (fixedPoints) fix fix' converge extends composeExtensions
|
||||||
makeExtensible makeExtensibleWithCustomName;
|
makeExtensible makeExtensibleWithCustomName;
|
||||||
inherit (attrsets) attrByPath hasAttrByPath setAttrByPath
|
inherit (attrsets) attrByPath hasAttrByPath setAttrByPath
|
||||||
getAttrFromPath attrVals attrValues catAttrs filterAttrs
|
getAttrFromPath attrVals attrValues getAttrs catAttrs filterAttrs
|
||||||
filterAttrsRecursive foldAttrs collect nameValuePair mapAttrs
|
filterAttrsRecursive foldAttrs collect nameValuePair mapAttrs
|
||||||
mapAttrs' mapAttrsToList mapAttrsRecursive mapAttrsRecursiveCond
|
mapAttrs' mapAttrsToList mapAttrsRecursive mapAttrsRecursiveCond
|
||||||
genAttrs isDerivation toDerivation optionalAttrs
|
genAttrs isDerivation toDerivation optionalAttrs
|
||||||
|
@ -24,6 +24,16 @@ rec {
|
|||||||
# for a concrete example.
|
# for a concrete example.
|
||||||
fix' = f: let x = f x // { __unfix__ = f; }; in x;
|
fix' = f: let x = f x // { __unfix__ = f; }; in x;
|
||||||
|
|
||||||
|
# Return the fixpoint that `f` converges to when called recursively, starting
|
||||||
|
# with the input `x`.
|
||||||
|
#
|
||||||
|
# nix-repl> converge (x: x / 2) 16
|
||||||
|
# 0
|
||||||
|
converge = f: x:
|
||||||
|
if (f x) == x
|
||||||
|
then x
|
||||||
|
else converge f (f x);
|
||||||
|
|
||||||
# Modify the contents of an explicitly recursive attribute set in a way that
|
# Modify the contents of an explicitly recursive attribute set in a way that
|
||||||
# honors `self`-references. This is accomplished with a function
|
# honors `self`-references. This is accomplished with a function
|
||||||
#
|
#
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
, postBuild ? null
|
, postBuild ? null
|
||||||
, document ? []
|
, document ? []
|
||||||
, meta ? {}
|
, meta ? {}
|
||||||
, groups ? ["default"]
|
, groups ? null
|
||||||
, ignoreCollisions ? false
|
, ignoreCollisions ? false
|
||||||
, buildInputs ? []
|
, buildInputs ? []
|
||||||
, ...
|
, ...
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
{ lib, gemConfig, ... }:
|
{ lib, gemConfig, ... }:
|
||||||
rec {
|
|
||||||
|
let
|
||||||
|
inherit (lib) attrValues concatMap converge filterAttrs getAttrs
|
||||||
|
intersectLists;
|
||||||
|
|
||||||
|
in rec {
|
||||||
bundlerFiles = {
|
bundlerFiles = {
|
||||||
gemfile ? null
|
gemfile ? null
|
||||||
, lockfile ? null
|
, lockfile ? null
|
||||||
@ -22,7 +27,19 @@ rec {
|
|||||||
else gemset;
|
else gemset;
|
||||||
};
|
};
|
||||||
|
|
||||||
filterGemset = {ruby, groups,...}: gemset: lib.filterAttrs (name: attrs: platformMatches ruby attrs && groupMatches groups attrs) gemset;
|
filterGemset = { ruby, groups, ... }: gemset:
|
||||||
|
let
|
||||||
|
platformGems = filterAttrs (_: platformMatches ruby) gemset;
|
||||||
|
directlyMatchingGems = filterAttrs (_: groupMatches groups) platformGems;
|
||||||
|
|
||||||
|
expandDependencies = gems:
|
||||||
|
let
|
||||||
|
depNames = concatMap (gem: gem.dependencies or []) (attrValues gems);
|
||||||
|
deps = getAttrs depNames platformGems;
|
||||||
|
in
|
||||||
|
gems // deps;
|
||||||
|
in
|
||||||
|
converge expandDependencies directlyMatchingGems;
|
||||||
|
|
||||||
platformMatches = {rubyEngine, version, ...}: attrs: (
|
platformMatches = {rubyEngine, version, ...}: attrs: (
|
||||||
!(attrs ? "platforms") ||
|
!(attrs ? "platforms") ||
|
||||||
@ -33,10 +50,9 @@ rec {
|
|||||||
) attrs.platforms
|
) attrs.platforms
|
||||||
);
|
);
|
||||||
|
|
||||||
groupMatches = groups: attrs: (
|
groupMatches = groups: attrs:
|
||||||
!(attrs ? "groups") ||
|
groups == null || !(attrs ? "groups") ||
|
||||||
builtins.any (gemGroup: builtins.any (group: group == gemGroup) groups) attrs.groups
|
(intersectLists (groups ++ [ "default" ]) attrs.groups) != [];
|
||||||
);
|
|
||||||
|
|
||||||
applyGemConfigs = attrs:
|
applyGemConfigs = attrs:
|
||||||
(if gemConfig ? "${attrs.gemName}"
|
(if gemConfig ? "${attrs.gemName}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user