Are `lib.platforms` legacy?

The lib/meta.nix file has had the following comment for over 8 years:

A `meta.platform` pattern is either

   1. (legacy) a system string.

   2. (modern) a pattern for the platform `parsed` field.

After that period of time, not many packages use the modern format:

# legacy
meta.platform = lib.platforms.unix;
# modern
meta.platform = lib.systems.inspect.patterns.isUnix;
# = [ {kernel={families={bsd={name="bsd";};};};}
#     {kernel={families={darwin{name="darwin";};};};}
#     {kernel={execFormat={name="elf";};families={};name="linux";};}
#     {kernel={execFormat={name="elf";};families={};name="solaris";};}
#     {kernel={execFormat={name="pe";};families={};name="cygwin";};}
#     {kernel={execFormat={name="elf";};families={};name="redox";};} ]
# legacy
meta.platform = [ "x86_64-linux" "aarch64-linux" ];
# modern
meta.platform = with lib.systems.inspect; patternLogicalAnd
  patterns.isLinux [ patterns.isx86_64 patterns.isAarch64 ];
# = [ {cpu={bits=64; family="x86";}; kernel={execFormat={name="elf";};families={}; name="linux";};}
#     {cpu={bits=64; family="arm";}; kernel={execFormat={name="elf";};families={}; name="linux";};} ]

I only learned of the modern format when I noticed that lib.lists.intersectLists lib.platforms.linux qemu.meta.platforms wasn’t working properly.

I’m curious what the benefit of the second platform specification is, as not many packages use it. Nixpkgs also has a finite list of supported platforms, so the flexibility isn’t strictly necessary here.

4 Likes

Good question! Another limitation of the style qemu just adopted is that it shows up as ‘This package does not list its available platforms.’ in search.

2 Likes

That is odd. The Nixpkgs search should be running something like

builtins.filter (lib.meta.availableOn qemu.meta.platforms) lib.systems.flakeExposed

to extract the “legacy” list of supported platforms for display.