query
On this page

platformMatch

lib.meta.platformMatch

Docs pulled from | This Revision | 10 minutes ago


Check to see if a platform is matched by the given meta.platforms element.

A meta.platform pattern is either

  1. (legacy) a system string.

  2. (modern) a pattern for the entire platform structure (see lib.systems.inspect.platformPatterns).

  3. (modern) a pattern for the platform parsed field (see lib.systems.inspect.patterns).

We can inject these into a pattern for the whole of a structured platform, and then match that.

Inputs

platform

1. Function argument

elem

2. Function argument

Examples

lib.meta.platformMatch usage example

lib.meta.platformMatch { system = "aarch64-darwin"; } "aarch64-darwin"
=> true

Noogle detected

Implementation

The following is the current implementation of this function.

platformMatch =
    platform: elem:
    (
      # Check with simple string comparison if elem was a string.
      #
      # The majority of comparisons done with this function will be against meta.platforms
      # which contains a simple platform string.
      #
      # Avoiding an attrset allocation results in significant  performance gains (~2-30) across the board in OfBorg
      # because this is a hot path for nixpkgs.
      if isString elem then
        platform ? system && elem == platform.system
      else
        matchAttrs (
          # Normalize platform attrset.
          if elem ? parsed then elem else { parsed = elem; }
        ) platform
    );