From ab2fe22124e9190e7b47638520268d24c7ac3c99 Mon Sep 17 00:00:00 2001 From: Michael Daniels Date: Sun, 10 May 2026 22:12:20 -0400 Subject: [PATCH] stdenv/check-meta: verify that licenses aren't derivations Among other things, "zlib" is a license, and it's difficult to debug the eval errors that occur when that derivation gets added to meta.licenses. --- pkgs/stdenv/generic/check-meta.nix | 19 +++++++++++-------- pkgs/stdenv/generic/meta-types.nix | 29 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/pkgs/stdenv/generic/check-meta.nix b/pkgs/stdenv/generic/check-meta.nix index af5eaac8f80a..91e40c365127 100644 --- a/pkgs/stdenv/generic/check-meta.nix +++ b/pkgs/stdenv/generic/check-meta.nix @@ -16,12 +16,10 @@ let filter findFirst getName - isDerivation length concatMap mutuallyExclusive optional - optionalString isAttrs isString warn @@ -308,15 +306,17 @@ let union int attrs - attrsOf any listOf bool record + intersection + not + derivation ; platforms = listOf (union [ str - (attrsOf any) + attrs ]); # see lib.meta.platformMatch in record { @@ -338,7 +338,10 @@ let let # TODO disallow `str` licenses, use a module licenseType = union [ - (attrsOf any) + (intersection [ + attrs + (not derivation) + ]) str ]; in @@ -347,9 +350,9 @@ let licenseType ]; sourceProvenance = listOf attrs; - maintainers = listOf (attrsOf any); # TODO use the maintainer type from lib/tests/maintainer-module.nix - nonTeamMaintainers = listOf (attrsOf any); # TODO use the maintainer type from lib/tests/maintainer-module.nix - teams = listOf (attrsOf any); # TODO similar to maintainers, use a teams type + maintainers = listOf attrs; # TODO use the maintainer type from lib/tests/maintainer-module.nix + nonTeamMaintainers = listOf attrs; # TODO use the maintainer type from lib/tests/maintainer-module.nix + teams = listOf attrs; # TODO similar to maintainers, use a teams type priority = int; pkgConfigModules = listOf str; inherit platforms; diff --git a/pkgs/stdenv/generic/meta-types.nix b/pkgs/stdenv/generic/meta-types.nix index 6e432d1ed609..1396243e3002 100644 --- a/pkgs/stdenv/generic/meta-types.nix +++ b/pkgs/stdenv/generic/meta-types.nix @@ -10,6 +10,7 @@ let isInt isAttrs isList + isDerivation all any attrNames @@ -103,6 +104,11 @@ lib.fix (self: { ) (attrNames attrs); }; + derivation = { + name = "derivation"; + verify = isDerivation; + }; + listOf = t: assert isTypeDef t; @@ -141,6 +147,29 @@ lib.fix (self: { verify = v: any (func: func v) funcs; }; + intersection = + types: + assert all isTypeDef types; + let + # Store a list of functions so we don't have to pay the cost of attrset lookups at runtime. + funcs = map (t: t.verify) types; + in + { + name = "intersection<${concatStringsSep "," (map (t: t.name) types)}>"; + verify = v: all (func: func v) funcs; + }; + + not = + t: + assert isTypeDef t; + let + inherit (t) verify; + in + { + name = "not<${t.name}>"; + verify = v: !(verify v); + }; + enum = values: assert isList values && all isString values;