@@ -13,10 +13,6 @@ let
getName = attrs : attrs . name or ( " ${ attrs . pname or " « n a m e - m i s s i n g » " } - ${ attrs . version or " « v e r s i o n - m i s s i n g » " } " ) ;
# See discussion at https://github.com/NixOS/nixpkgs/pull/25304#issuecomment-298385426
# for why this defaults to false, but I (@copumpkin) want to default it to true soon.
shouldCheckMeta = config . checkMeta or false ;
allowUnfree = config . allowUnfree
|| builtins . getEnv " N I X P K G S _ A L L O W _ U N F R E E " = = " 1 " ;
@@ -248,6 +244,16 @@ let
isEnabled = lib . findFirst ( x : x = = reason ) null showWarnings ;
in if isEnabled != null then builtins . trace msg true else true ;
# A shallow type check. We are using NixOS'
# option types here, which however have the major drawback
# of not providing full type checking (part of the type check is
# done by the module evaluation itself). Therefore, the checks
# will not recurse into attributes.
# We still provide the full type for documentation
# purposes and in the hope that they will be used eventually.
# See https://github.com/NixOS/nixpkgs/pull/191171 for an attempt
# to fix this, or mkOptionType in lib/types.nix for more information.
metaTypes = with lib . types ; rec {
# These keys are documented
description = str ;
@@ -297,17 +303,23 @@ let
badPlatforms = platforms ;
} ;
# WARNING: this does not check inner values of the attribute, like list elements or nested attributes.
# See metaTypes above and mkOptionType in lib/types.nix for more information
checkMetaAttr = k : v :
if metaTypes ? ${ k } then
if metaTypes . ${ k } . check v then null else " k e y ' ${ k } ' h a s a v a l u e ${ toString v } o f a n i n v a l i d t y p e ${ builtins . typeOf v } ; e x p e c t e d ${ metaTypes . ${ k } . description } "
else " k e y ' ${ k } ' i s u n r e c o g n i z e d ; e x p e c t e d o n e o f : \n \t [ ${ lib . concatMapStringsSep " , " ( x : " ' ${ x } ' " ) ( lib . attrNames metaTypes ) } ] " ;
checkMeta = meta : if shouldCheckMeta then lib . remove null ( lib . mapAttrsToList checkMetaAttr meta ) else [ ] ;
if metaTypes . ${ k } . check v then
null
else
" k e y ' m e t a . ${ k } ' h a s a v a l u e o f i n v a l i d t y p e ${ builtins . typeOf v } ; e x p e c t e d ${ metaTypes . ${ k } . description } "
else
" k e y ' m e t a . ${ k } ' i s u n r e c o g n i z e d ; e x p e c t e d o n e o f : \n \t [ ${ lib . concatMapStringsSep " , " ( x : " ' ${ x } ' " ) ( lib . attrNames metaTypes ) } ] " ;
checkMeta = meta : if config . checkMeta then lib . remove null ( lib . mapAttrsToList checkMetaAttr meta ) else [ ] ;
checkOutputsToInstall = attrs : let
expectedOutputs = attrs . meta . outputsToInstall or [ ] ;
actualOutputs = attrs . outputs or [ " o u t " ] ;
missingOutputs = builtins . filter ( output : ! builtins . elem output actualOutputs ) expectedOutputs ;
in if shouldC heckMeta
in if config . c heckMeta
then builtins . length missingOutputs > 0
else false ;
@@ -326,7 +338,17 @@ let
unsupported = hasUnsupportedPlatform attrs ;
insecure = isMarkedInsecure attrs ;
}
// ( if hasDeniedUnfreeLicense attrs && ! ( hasAllowlistedLicense attrs ) then
// (
# Check meta attribute types first, to make sure it is always called even when there are other issues
# Note that this is not a full type check and functions below still need to by careful about their inputs!
let res = checkMeta ( attrs . meta or { } ) ; in if res != [ ] then
{ valid = " n o " ; reason = " u n k n o w n - m e t a " ; errormsg = " h a s a n i n v a l i d m e t a a t t r s e t : ${ lib . concatMapStrings ( x : " \n \t - " + x ) res } " ; }
# --- Put checks that cannot be ignored here ---
else if checkOutputsToInstall attrs then
{ valid = " n o " ; reason = " b r o k e n - o u t p u t s " ; errormsg = " h a s i n v a l i d m e t a . o u t p u t s T o I n s t a l l " ; }
# --- Put checks that can be ignored here ---
else if hasDeniedUnfreeLicense attrs && ! ( hasAllowlistedLicense attrs ) then
{ valid = " n o " ; reason = " u n f r e e " ; errormsg = " h a s a n u n f r e e l i c e n s e ( ‘ ${ showLicense attrs . meta . license } ’ ) " ; }
else if hasBlocklistedLicense attrs then
{ valid = " n o " ; reason = " b l o c k l i s t e d " ; errormsg = " h a s a b l o c k l i s t e d l i c e n s e ( ‘ ${ showLicense attrs . meta . license } ’ ) " ; }
@@ -338,10 +360,7 @@ let
{ valid = " n o " ; reason = " u n s u p p o r t e d " ; errormsg = " i s n o t s u p p o r t e d o n ‘ ${ hostPlatform . system } ’ " ; }
else if ! ( hasAllowedInsecure attrs ) then
{ valid = " n o " ; reason = " i n s e c u r e " ; errormsg = " i s m a r k e d a s i n s e c u r e " ; }
else if checkOutputsToInstall attrs then
{ valid = " n o " ; reason = " b r o k e n - o u t p u t s " ; errormsg = " h a s i n v a l i d m e t a . o u t p u t s T o I n s t a l l " ; }
else let res = checkMeta ( attrs . meta or { } ) ; in if res != [ ] then
{ valid = " n o " ; reason = " u n k n o w n - m e t a " ; errormsg = " h a s a n i n v a l i d m e t a a t t r s e t : ${ lib . concatMapStrings ( x : " \n \t - " + x ) res } " ; }
# --- warnings ---
# Please also update the type in /pkgs/top-level/config.nix alongside this.
else if hasNoMaintainers attrs then