From 618b182d4edc64f894f1288d4da6c4d90648dcd4 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sun, 22 Jan 2023 15:13:20 -0800 Subject: [PATCH] lib/systems: add doublesFromPattern(s) --- lib/systems/default.nix | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/systems/default.nix b/lib/systems/default.nix index 78ccd50ba79a5..3482b87efc66c 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -27,6 +27,25 @@ rec { let removeFunctions = a: lib.filterAttrs (_: v: !builtins.isFunction v) a; in a: b: removeFunctions a == removeFunctions b; + # This function returns the elements of `systems.doubles.all` + # which match its argument, which can be either a pattern (see + # `lib.systems.inspect.patterns`) or a nix-double string. It is + # used mainly for backward compatibility with existing code that + # expects `meta.{bad,hydra,""}platforms` to be a list of strings. + doublesFromPattern = pattern: + if lib.isString pattern + then [pattern] + else lib.filter + (double: lib.meta.platformMatch (elaborate double) pattern) + doubles.all; + + # like above, but applied to a (disjunctive) list, with some + # optimizations for common cases on Hydra + doublesFromPatterns = patterns: + if lib.all lib.isString patterns + then patterns + else lib.concatMap doublesFromPattern patterns; + /* List of all Nix system doubles the nixpkgs flake will expose the package set for. All systems listed here must be supported by nixpkgs as `localSystem`.