query
On this page

toSPDX

lib.licenses.toSPDX

Docs pulled from | This Revision | 31 minutes ago


Nixpkgs manual

Convert a license expression to an SPDX license expression string.

Example

toSPDX (with lib.licenses; AND [ ncsa (WITH asl20 llvm-exception) ])
=> "NCSA AND (Apache-2.0 WITH LLVM-exception)"

Type

toSPDX :: AttrSet -> String

Arguments

  • [license] License expression which to convert to spdx expression

Noogle detected

Implementation

The following is the current implementation of this function.

toSPDX =
    license:
    let
      mkBracket =
        x:
        if x.licenseType == "compound" || x.licenseType == "exception" then "(${toSPDX x})" else toSPDX x;
    in
    if license.licenseType == "simple" then
      license.spdxId or "LicenseRef-nixos-${license.shortName}"
    else if license.licenseType == "compound" then
      lib.concatMapStringsSep " ${license.operator} " (x: mkBracket x) license.licenses
    else if license.licenseType == "exception" then
      "${mkBracket license.license} ${license.operator} ${mkBracket license.exception}"
    else if license.licenseType == "plus" then
      "${mkBracket license.license}${license.operator}"
    else
      throw "Unknown license type";