Unverified Commit 6966e417 authored by jopejoe1's avatar jopejoe1 Committed by GitHub
Browse files

check-meta.nix: fix check for license type attr (#511610)

parents 0a1171a2 ca779c6d
Loading
Loading
Loading
Loading
+84 −61
Original line number Diff line number Diff line
@@ -22,14 +22,17 @@ let
    assertMsg
    generators
    licenses
    nameValuePair
    recurseIntoAttrs
    replaceString
    ;

  mkUnfreePkg = name: {
  mkPkg = name: license: {
    pname = name;
    version = "1.0";
    meta.license = licenses.unfree;
    meta.license = license;
  };

  assertValidity =
    {
      nixpkgsConfig,
@@ -52,16 +55,16 @@ let
      toPretty = generators.toPretty { };
    in
    assertMsg (actual.success == expected) ''
      Expected validity of package ${lib.getName pkg} to be ${toPretty expected},
      but got ${toPretty actual} with config:
      Expected validity of package '${lib.getName pkg}' with unfree license
      '${licenses.toSPDX pkg.meta.license}' to be ${toPretty expected}, but got
      ${toPretty actual}
      with config:
      ${toPretty nixpkgsConfig}
    '';

  runAssertions = assertions: lib.deepSeq assertions "";

in
recurseIntoAttrs {

  mkTests = mkUnfreePkg: {
    allowOnlyFreePackagesByDefault = assertValidity {
      nixpkgsConfig = { };
      pkg = mkUnfreePkg "forbidden";
@@ -125,4 +128,24 @@ recurseIntoAttrs {
          expected = false;
        })
      ];
}
  };

  unfreeLicenses = [
    licenses.unfree
    (licenses.AND [
      licenses.free
      licenses.unfree
    ])
  ];
in

recurseIntoAttrs (
  builtins.listToAttrs (
    map (
      license:
      nameValuePair (replaceString " " "-" (licenses.toSPDX license)) (
        recurseIntoAttrs (mkTests (name: mkPkg name license))
      )
    ) unfreeLicenses
  )
)
+2 −2
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ let
      && (
        if isList attrs.meta.license then
          any (l: elem l list) attrs.meta.license
        else if attrs.meta.license ? "type" then
        else if attrs.meta.license ? "licenseType" then
          lib.licenses.containsLicenses list attrs.meta.license
        else
          elem attrs.meta.license list
@@ -105,7 +105,7 @@ let

  isUnfree =
    licenses:
    if isAttrs licenses && licenses ? "type" then
    if isAttrs licenses && licenses ? "licenseType" then
      !(lib.licenses.isFree licenses)
    else if isAttrs licenses then
      !(licenses.free or true)