···248248### `lib.sourceTypes.binaryBytecode` {#lib.sourceTypes.binaryBytecode}
249249250250Code to run on a VM interpreter or JIT compiled into bytecode by a third party. This includes packages which download Java `.jar` files from another source.
251251-252252-## Software identifiers {#sec-meta-identifiers}
253253-254254-Package's `meta.identifiers` attribute specifies information about software identifiers associated with this package. Software identifiers are used, for example:
255255-* to generate Software Bill of Materials (SBOM) that lists all components used to build the software, which can later be used to perform vulnerability or license analysis of the resulting software;
256256-* to lookup software in different vulnerability databases or report new vulnerabilities to them.
257257-258258-Overriding the default `meta.identifiers` attribute is optional, but it is recommended to fill in pieces to help tools mentioned above get precise data.
259259-For example, we could get automatic notifications about potential vulnerabilities for users in the future.
260260-All identifiers specified in `meta.identifiers` are expected to be unambiguous and valid.
261261-262262-`meta.identifiers` contains `v1` attribute which is an attribute set that guarantees backward compatibility of its constituents. Right now it contains copies of all other attributes in `meta.identifiers`.
263263-264264-### CPE {#sec-meta-identifiers-cpe}
265265-266266-Common Platform Enumeration (CPE) is a specification maintained by NIST as part of the Security Content Automation Protocol (SCAP). It is used to identify software in National Vulnerabilities Database (NVD, https://nvd.nist.gov) and other vulnerability databases.
267267-268268-Current version of CPE 2.3 consists of 13 parts:
269269-270270-```
271271-cpe:2.3:a:<vendor>:<product>:<version>:<update>:<edition>:<language>:<sw_edition>:<target_sw>:<target_hw>:<other>
272272-```
273273-274274-Some of them are as follows:
275275-276276-* *CPE version* - current version of CPE is `2.3`
277277-* *part* - usually in Nixpkgs `a` for "application", can also be `o` for "operating system" or `h` for "hardware"
278278-* *vendor* - can point to the source of the package, or to Nixpkgs itself
279279-* *product* - name of the package
280280-* *version* - version of the package
281281-* *update* - name of the latest update, can be a patch version for semantically versioned packages
282282-* *edition* - any additional specification about the version
283283-284284-You can find information about all of these attributes in the [official specification](https://csrc.nist.gov/projects/security-content-automation-protocol/specifications/cpe/naming) (heading 5.3.3, pages 11-13).
285285-286286-Any fields that don't have a value are set to either `-` if the value is not available or `*` when the field can match any value.
287287-288288-For example, for glibc 2.40.1 CPE would be `cpe:2.3:a:gnu:glibc:2.40:1:*:*:*:*:*:*`.
289289-290290-#### `meta.identifiers.cpeParts` {#var-meta-identifiers-cpeParts}
291291-292292-This attribute contains an attribute set of all parts of the CPE for this package. Most of the parts default to `*` (match any value), with some exceptions:
293293-294294-* `part` defaults to `a` (application), can also be set to `o` for operating systems, for example, Linux kernel, or to `h` for hardware
295295-* `vendor` cannot be deduced from other sources, so it must be specified by the package author
296296-* `product` defaults to provided derivation's `pname` attribute and must be provided explicitly if `pname` is missing
297297-* `version` and `update` have no defaults and should be specified explicitly or using helper functions, when missing, `cpe` attribute will be empty, and all possible guesses using helper functions will be in `possibleCPEs` attribute.
298298-299299-It is up to the package author to make sure all parts are correct and match expected values in [NVD dictionary](https://nvd.nist.gov/products/cpe). Unknown values can be skipped, which would leave them with the default value of `*`.
300300-301301-Following functions help with filling out `version` and `update` fields:
302302-303303-* [`lib.meta.cpeFullVersionWithVendor`](#function-library-lib.meta.cpeFullVersionWithVendor)
304304-* [`lib.meta.cpePatchVersionInUpdateWithVendor`](#function-library-lib.meta.cpePatchVersionInUpdateWithVendor)
305305-306306-For many packages to make CPE available it should be enough to specify only:
307307-308308-```nix
309309-{
310310- # ...
311311- meta.identifiers.cpeParts = lib.meta.cpePatchVersionInUpdateWithVendor vendor version;
312312-}
313313-```
314314-315315-#### `meta.identifiers.cpe` {#var-meta-identifiers-cpe}
316316-317317-A readonly attribute that concatenates all CPE parts in one string.
318318-319319-#### `meta.identifiers.possibleCPEs` {#var-meta-identifiers-possibleCPEs}
320320-321321-A readonly attribute containing the list of guesses for what CPE for this package can look like. It includes all variants of version handling mentioned above. Each item is an attrset with attributes `cpeParts` and `cpe` for each guess.
+1-188
lib/meta.nix
···1515 assertMsg
1616 ;
1717 inherit (lib.attrsets) mapAttrs' filterAttrs;
1818- inherit (builtins)
1919- isString
2020- match
2121- typeOf
2222- elemAt
2323- ;
1818+ inherit (builtins) isString match typeOf;
24192520in
2621rec {
···489484 assert assertMsg (match ".*/.*" y == null)
490485 "lib.meta.getExe': The second argument \"${y}\" is a nested path with a \"/\" character, but it should just be the name of the executable instead.";
491486 "${getBin x}/bin/${y}";
492492-493493- /**
494494- Generate [CPE parts](#var-meta-identifiers-cpeParts) from inputs. Copies `vendor` and `version` to the output, and sets `update` to `*`.
495495-496496- # Inputs
497497-498498- `vendor`
499499-500500- : package's vendor
501501-502502- `version`
503503-504504- : package's version
505505-506506- # Type
507507-508508- ```
509509- cpeFullVersionWithVendor :: string -> string -> AttrSet
510510- ```
511511-512512- # Examples
513513- :::{.example}
514514- ## `lib.meta.cpeFullVersionWithVendor` usage example
515515-516516- ```nix
517517- lib.meta.cpeFullVersionWithVendor "gnu" "1.2.3"
518518- => {
519519- vendor = "gnu";
520520- version = "1.2.3";
521521- update = "*";
522522- }
523523- ```
524524-525525- :::
526526- :::{.example}
527527- ## `lib.meta.cpeFullVersionWithVendor` usage in derivations
528528-529529- ```nix
530530- mkDerivation rec {
531531- version = "1.2.3";
532532- # ...
533533- meta = {
534534- # ...
535535- identifiers.cpeParts = lib.meta.cpeFullVersionWithVendor "gnu" version;
536536- };
537537- }
538538- ```
539539- :::
540540- */
541541- cpeFullVersionWithVendor = vendor: version: {
542542- inherit vendor version;
543543- update = "*";
544544- };
545545-546546- /**
547547- Alternate version of [`lib.meta.cpePatchVersionInUpdateWithVendor`](#function-library-lib.meta.cpePatchVersionInUpdateWithVendor).
548548- If `cpePatchVersionInUpdateWithVendor` succeeds, returns an attribute set with `success` set to `true` and `value` set to the result.
549549- Otherwise, `success` is set to `false` and `error` is set to the string representation of the error.
550550-551551- # Inputs
552552-553553- `vendor`
554554-555555- : package's vendor
556556-557557- `version`
558558-559559- : package's version
560560-561561- # Type
562562-563563- ```
564564- tryCPEPatchVersionInUpdateWithVendor :: string -> string -> AttrSet
565565- ```
566566-567567- # Examples
568568- :::{.example}
569569- ## `lib.meta.tryCPEPatchVersionInUpdateWithVendor` usage example
570570-571571- ```nix
572572- lib.meta.tryCPEPatchVersionInUpdateWithVendor "gnu" "1.2.3"
573573- => {
574574- success = true;
575575- value = {
576576- vendor = "gnu";
577577- version = "1.2";
578578- update = "3";
579579- };
580580- }
581581- ```
582582-583583- :::
584584- :::{.example}
585585- ## `lib.meta.cpePatchVersionInUpdateWithVendor` error example
586586-587587- ```nix
588588- lib.meta.tryCPEPatchVersionInUpdateWithVendor "gnu" "5.3p0"
589589- => {
590590- success = false;
591591- error = "version 5.3p0 doesn't match regex `([0-9]+\\.[0-9]+)\\.([0-9]+)`";
592592- }
593593- ```
594594-595595- :::
596596- */
597597- tryCPEPatchVersionInUpdateWithVendor =
598598- vendor: version:
599599- let
600600- regex = "([0-9]+\\.[0-9]+)\\.([0-9]+)";
601601- # we have to call toString here in case version is an attrset with __toString attribute
602602- versionMatch = builtins.match regex (toString version);
603603- in
604604- if versionMatch == null then
605605- {
606606- success = false;
607607- error = "version ${version} doesn't match regex `${regex}`";
608608- }
609609- else
610610- {
611611- success = true;
612612- value = {
613613- inherit vendor;
614614- version = elemAt versionMatch 0;
615615- update = elemAt versionMatch 1;
616616- };
617617- };
618618-619619- /**
620620- Generate [CPE parts](#var-meta-identifiers-cpeParts) from inputs. Copies `vendor` to the result. When `version` matches `X.Y.Z` where all parts are numerical, sets `version` and `update` fields to `X.Y` and `Z`. Throws an error if the version doesn't match the expected template.
621621-622622- # Inputs
623623-624624- `vendor`
625625-626626- : package's vendor
627627-628628- `version`
629629-630630- : package's version
631631-632632- # Type
633633-634634- ```
635635- cpePatchVersionInUpdateWithVendor :: string -> string -> AttrSet
636636- ```
637637-638638- # Examples
639639- :::{.example}
640640- ## `lib.meta.cpePatchVersionInUpdateWithVendor` usage example
641641-642642- ```nix
643643- lib.meta.cpePatchVersionInUpdateWithVendor "gnu" "1.2.3"
644644- => {
645645- vendor = "gnu";
646646- version = "1.2";
647647- update = "3";
648648- }
649649- ```
650650-651651- :::
652652- :::{.example}
653653- ## `lib.meta.cpePatchVersionInUpdateWithVendor` usage in derivations
654654-655655- ```nix
656656- mkDerivation rec {
657657- version = "1.2.3";
658658- # ...
659659- meta = {
660660- # ...
661661- identifiers.cpeParts = lib.meta.cpePatchVersionInUpdateWithVendor "gnu" version;
662662- };
663663- }
664664- ```
665665-666666- :::
667667- */
668668- cpePatchVersionInUpdateWithVendor =
669669- vendor: version:
670670- let
671671- result = tryCPEPatchVersionInUpdateWithVendor vendor version;
672672- in
673673- if result.success then result.value else throw result.error;
674487}
···1111 inherit (lib)
1212 all
1313 attrNames
1414- attrValues
1514 concatMapStrings
1615 concatMapStringsSep
1716 concatStrings
···38373938 inherit (lib.meta)
4039 availableOn
4141- cpeFullVersionWithVendor
4242- tryCPEPatchVersionInUpdateWithVendor
4340 ;
44414542 inherit (lib.generators)
···440437 # Used for the original location of the maintainer and team attributes to assist with pings.
441438 maintainersPosition = any;
442439 teamsPosition = any;
443443-444444- identifiers = attrs;
445440 };
446441447442 checkMetaAttr =
···575570 else
576571 validYes;
577572578578- # Helper functions and declarations to handle identifiers, extracted to reduce allocations
579579- hasAllCPEParts = cpeParts: !any isNull (attrValues cpeParts);
580580- makeCPE =
581581- cpeParts:
582582- "cpe:2.3:${cpeParts.part}:${cpeParts.vendor}:${cpeParts.product}:${cpeParts.version}:${cpeParts.update}:${cpeParts.edition}:${cpeParts.sw_edition}:${cpeParts.target_sw}:${cpeParts.target_hw}:${cpeParts.language}:${cpeParts.other}";
583583- possibleCPEPartsFuns = [
584584- (vendor: version: {
585585- success = true;
586586- value = cpeFullVersionWithVendor vendor version;
587587- })
588588- tryCPEPatchVersionInUpdateWithVendor
589589- ];
590590-591573 # The meta attribute is passed in the resulting attribute set,
592574 # but it's not part of the actual derivation, i.e., it's not
593575 # passed to the builder and is not a dependency. But since we
···651633 # if you add a new maintainer or team attribute please ensure that this expectation is still met.
652634 maintainers =
653635 attrs.meta.maintainers or [ ] ++ concatMap (team: team.members or [ ]) attrs.meta.teams or [ ];
654654-655655- identifiers =
656656- let
657657- defaultCPEParts = {
658658- part = "a";
659659- vendor = null;
660660- product = attrs.pname or null;
661661- version = null;
662662- update = null;
663663- edition = "*";
664664- sw_edition = "*";
665665- target_sw = "*";
666666- target_hw = "*";
667667- language = "*";
668668- other = "*";
669669- };
670670-671671- cpeParts = defaultCPEParts // attrs.meta.identifiers.cpeParts or { };
672672- cpe = if hasAllCPEParts cpeParts then makeCPE cpeParts else null;
673673-674674- possibleCPEs =
675675- if cpe != null then
676676- [ { inherit cpeParts cpe; } ]
677677- else if attrs.meta.identifiers.cpeParts.vendor or null == null || attrs.version or null == null then
678678- [ ]
679679- else
680680- concatMap (
681681- f:
682682- let
683683- result = f attrs.meta.identifiers.cpeParts.vendor attrs.version;
684684- # Note that attrs.meta.identifiers.cpeParts at this point can include defaults with user overrides.
685685- # Since we can't split them apart, user overrides don't apply to possibleCPEs.
686686- guessedParts = cpeParts // result.value;
687687- in
688688- optional (result.success && (hasAllCPEParts guessedParts)) {
689689- cpeParts = guessedParts;
690690- cpe = (makeCPE guessedParts);
691691- }
692692- ) possibleCPEPartsFuns;
693693- v1 = { inherit cpeParts cpe possibleCPEs; };
694694- in
695695- v1
696696- // {
697697- inherit v1;
698698- };
699636700637 # Expose the result of the checks for everyone to see.
701638 unfree = hasUnfreeLicense attrs;