How does flake-parts `withSystem` work?

Hey,

how does flake-parts’s withSystem work?

The docs just say:

Enter the scope of a system. Example:

and give the snippet

{ withSystem, inputs, ... }:
{
  # perSystem = { ... }: { config.packages.hello = ...; };

  flake.nixosConfigurations.foo = withSystem "x86_64-linux" (ctx@{ config, inputs', pkgs, ... }: {...}

Is it magic or is it some simple attribute set getter exposed in the form of lambda?

I can’t tell form the source code: https://github.com/hercules-ci/flake-parts/blob/34fed993f1674c8d06d58b37ce1e0fe5eebcb9f5/modules/withSystem.nix#L8.

Thanks!

The passed in attributes are contextualized to the given system. Similar to how perSystems attributes are, with the difference, that you are in charge to choose the correct system and only that one system is used, rather than automatically for all defined systems.