Merge pull request #34444 from obsidiansystems/meta-check
lib: Fix #30902
This commit is contained in:
commit
2fa2197a96
|
@ -47,7 +47,7 @@ let
|
||||||
filesystem = callLibs ./filesystem.nix;
|
filesystem = callLibs ./filesystem.nix;
|
||||||
|
|
||||||
# back-compat aliases
|
# back-compat aliases
|
||||||
platforms = systems.doubles;
|
platforms = systems.forMeta;
|
||||||
|
|
||||||
inherit (builtins) add addErrorContext attrNames
|
inherit (builtins) add addErrorContext attrNames
|
||||||
concatLists deepSeq elem elemAt filter genericClosure genList
|
concatLists deepSeq elem elemAt filter genericClosure genList
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
rec {
|
rec {
|
||||||
doubles = import ./doubles.nix { inherit lib; };
|
doubles = import ./doubles.nix { inherit lib; };
|
||||||
|
forMeta = import ./for-meta.nix { inherit lib; };
|
||||||
parse = import ./parse.nix { inherit lib; };
|
parse = import ./parse.nix { inherit lib; };
|
||||||
inspect = import ./inspect.nix { inherit lib; };
|
inspect = import ./inspect.nix { inherit lib; };
|
||||||
platforms = import ./platforms.nix { inherit lib; };
|
platforms = import ./platforms.nix { inherit lib; };
|
||||||
|
|
|
@ -30,14 +30,14 @@ in rec {
|
||||||
aarch64 = filterDoubles predicates.isAarch64;
|
aarch64 = filterDoubles predicates.isAarch64;
|
||||||
x86 = filterDoubles predicates.isx86;
|
x86 = filterDoubles predicates.isx86;
|
||||||
i686 = filterDoubles predicates.isi686;
|
i686 = filterDoubles predicates.isi686;
|
||||||
mips = filterDoubles predicates.isMips;
|
|
||||||
x86_64 = filterDoubles predicates.isx86_64;
|
x86_64 = filterDoubles predicates.isx86_64;
|
||||||
|
mips = filterDoubles predicates.isMips;
|
||||||
|
|
||||||
cygwin = filterDoubles predicates.isCygwin;
|
cygwin = filterDoubles predicates.isCygwin;
|
||||||
darwin = filterDoubles predicates.isDarwin;
|
darwin = filterDoubles predicates.isDarwin;
|
||||||
freebsd = filterDoubles predicates.isFreeBSD;
|
freebsd = filterDoubles predicates.isFreeBSD;
|
||||||
# Should be better, but MinGW is unclear, and HURD is bit-rotted.
|
# Should be better, but MinGW is unclear, and HURD is bit-rotted.
|
||||||
gnu = filterDoubles (matchAttrs { kernel = parse.kernels.linux; abi = parse.abis.gnu; });
|
gnu = filterDoubles (matchAttrs { kernel = parse.kernels.linux; abi = parse.abis.gnu; });
|
||||||
illumos = filterDoubles predicates.isSunOS;
|
illumos = filterDoubles predicates.isSunOS;
|
||||||
linux = filterDoubles predicates.isLinux;
|
linux = filterDoubles predicates.isLinux;
|
||||||
netbsd = filterDoubles predicates.isNetBSD;
|
netbsd = filterDoubles predicates.isNetBSD;
|
||||||
|
|
27
lib/systems/for-meta.nix
Normal file
27
lib/systems/for-meta.nix
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
{ lib }:
|
||||||
|
let
|
||||||
|
inherit (lib.systems) parse;
|
||||||
|
inherit (lib.systems.inspect) patterns;
|
||||||
|
|
||||||
|
in rec {
|
||||||
|
inherit (lib.systems.doubles) all mesaPlatforms;
|
||||||
|
none = [];
|
||||||
|
|
||||||
|
arm = [ patterns.Arm ];
|
||||||
|
aarch64 = [ patterns.Aarch64 ];
|
||||||
|
x86 = [ patterns.x86 ];
|
||||||
|
i686 = [ patterns.i686 ];
|
||||||
|
x86_64 = [ patterns.x86_64 ];
|
||||||
|
mips = [ patterns.Mips ];
|
||||||
|
|
||||||
|
cygwin = [ patterns.Cygwin ];
|
||||||
|
darwin = [ patterns.Darwin ];
|
||||||
|
freebsd = [ patterns.FreeBSD ];
|
||||||
|
# Should be better, but MinGW is unclear, and HURD is bit-rotted.
|
||||||
|
gnu = [ { kernel = parse.kernels.linux; abi = parse.abis.gnu; } ];
|
||||||
|
illumos = [ patterns.SunOS ];
|
||||||
|
linux = [ patterns.Linux ];
|
||||||
|
netbsd = [ patterns.NetBSD ];
|
||||||
|
openbsd = [ patterns.OpenBSD ];
|
||||||
|
unix = patterns.Unix; # Actually a list
|
||||||
|
}
|
|
@ -1,11 +1,9 @@
|
||||||
# Checks derivation meta and attrs for problems (like brokenness,
|
# Checks derivation meta and attrs for problems (like brokenness,
|
||||||
# licenses, etc).
|
# licenses, etc).
|
||||||
|
|
||||||
{ lib, config, system, meta, derivationArg, mkDerivationArg }:
|
{ lib, config, hostPlatform, meta }:
|
||||||
|
|
||||||
let
|
let
|
||||||
attrs = mkDerivationArg; # TODO: probably get rid of passing this one
|
|
||||||
|
|
||||||
# See discussion at https://github.com/NixOS/nixpkgs/pull/25304#issuecomment-298385426
|
# 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.
|
# for why this defaults to false, but I (@copumpkin) want to default it to true soon.
|
||||||
shouldCheckMeta = config.checkMeta or false;
|
shouldCheckMeta = config.checkMeta or false;
|
||||||
|
@ -123,7 +121,7 @@ let
|
||||||
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
handleEvalIssue = { reason , errormsg ? "" }:
|
handleEvalIssue = attrs: { reason , errormsg ? "" }:
|
||||||
let
|
let
|
||||||
msg = ''
|
msg = ''
|
||||||
Package ‘${attrs.name or "«name-missing»"}’ in ${pos_str} ${errormsg}, refusing to evaluate.
|
Package ‘${attrs.name or "«name-missing»"}’ in ${pos_str} ${errormsg}, refusing to evaluate.
|
||||||
|
@ -146,7 +144,7 @@ let
|
||||||
license = either (listOf lib.types.attrs) (either lib.types.attrs str);
|
license = either (listOf lib.types.attrs) (either lib.types.attrs str);
|
||||||
maintainers = listOf (attrsOf str);
|
maintainers = listOf (attrsOf str);
|
||||||
priority = int;
|
priority = int;
|
||||||
platforms = listOf str;
|
platforms = listOf (either str lib.systems.parsed.types.system);
|
||||||
hydraPlatforms = listOf str;
|
hydraPlatforms = listOf str;
|
||||||
broken = bool;
|
broken = bool;
|
||||||
|
|
||||||
|
@ -175,6 +173,11 @@ let
|
||||||
else "key '${k}' is unrecognized; expected one of: \n\t [${lib.concatMapStringsSep ", " (x: "'${x}'") (lib.attrNames metaTypes)}]";
|
else "key '${k}' is unrecognized; expected one of: \n\t [${lib.concatMapStringsSep ", " (x: "'${x}'") (lib.attrNames metaTypes)}]";
|
||||||
checkMeta = meta: if shouldCheckMeta then lib.remove null (lib.mapAttrsToList checkMetaAttr meta) else [];
|
checkMeta = meta: if shouldCheckMeta then lib.remove null (lib.mapAttrsToList checkMetaAttr meta) else [];
|
||||||
|
|
||||||
|
checkPlatform = attrs: let
|
||||||
|
raw = attrs.meta.platforms;
|
||||||
|
uniform = map (x: if builtins.isString x then { system = x; } else { parsed = x; }) raw;
|
||||||
|
in lib.any (pat: lib.matchAttrs pat hostPlatform) uniform;
|
||||||
|
|
||||||
# Check if a derivation is valid, that is whether it passes checks for
|
# Check if a derivation is valid, that is whether it passes checks for
|
||||||
# e.g brokenness or license.
|
# e.g brokenness or license.
|
||||||
#
|
#
|
||||||
|
@ -188,19 +191,21 @@ let
|
||||||
{ valid = false; reason = "blacklisted"; errormsg = "has a blacklisted license (‘${showLicense attrs.meta.license}’)"; }
|
{ valid = false; reason = "blacklisted"; errormsg = "has a blacklisted license (‘${showLicense attrs.meta.license}’)"; }
|
||||||
else if !allowBroken && attrs.meta.broken or false then
|
else if !allowBroken && attrs.meta.broken or false then
|
||||||
{ valid = false; reason = "broken"; errormsg = "is marked as broken"; }
|
{ valid = false; reason = "broken"; errormsg = "is marked as broken"; }
|
||||||
else if !allowUnsupportedSystem && !allowBroken && attrs.meta.platforms or null != null && !lib.lists.elem system attrs.meta.platforms then
|
else if !allowUnsupportedSystem && !allowBroken && attrs.meta.platforms or null != null && !(checkPlatform attrs) then
|
||||||
{ valid = false; reason = "broken"; errormsg = "is not supported on ‘${system}’"; }
|
{ valid = false; reason = "broken"; errormsg = "is not supported on ‘${hostPlatform.config}’"; }
|
||||||
else if !(hasAllowedInsecure attrs) then
|
else if !(hasAllowedInsecure attrs) then
|
||||||
{ valid = false; reason = "insecure"; errormsg = "is marked as insecure"; }
|
{ valid = false; reason = "insecure"; errormsg = "is marked as insecure"; }
|
||||||
else let res = checkMeta (attrs.meta or {}); in if res != [] then
|
else let res = checkMeta (attrs.meta or {}); in if res != [] then
|
||||||
{ valid = false; reason = "unknown-meta"; errormsg = "has an invalid meta attrset:${lib.concatMapStrings (x: "\n\t - " + x) res}"; }
|
{ valid = false; reason = "unknown-meta"; errormsg = "has an invalid meta attrset:${lib.concatMapStrings (x: "\n\t - " + x) res}"; }
|
||||||
else { valid = true; };
|
else { valid = true; };
|
||||||
|
|
||||||
validity = checkValidity attrs;
|
assertValidity = attrs: let
|
||||||
|
validity = checkValidity attrs;
|
||||||
|
in validity // {
|
||||||
|
# Throw an error if trying to evaluate an non-valid derivation
|
||||||
|
handled = if !validity.valid
|
||||||
|
then handleEvalIssue attrs (removeAttrs validity ["valid"])
|
||||||
|
else true;
|
||||||
|
};
|
||||||
|
|
||||||
in validity // {
|
in assertValidity
|
||||||
# Throw an error if trying to evaluate an non-valid derivation
|
|
||||||
handled = if !validity.valid
|
|
||||||
then handleEvalIssue (removeAttrs validity ["valid"])
|
|
||||||
else true;
|
|
||||||
}
|
|
||||||
|
|
|
@ -204,12 +204,11 @@ rec {
|
||||||
});
|
});
|
||||||
|
|
||||||
validity = import ./check-meta.nix {
|
validity = import ./check-meta.nix {
|
||||||
inherit lib config meta derivationArg;
|
inherit lib config meta;
|
||||||
mkDerivationArg = attrs;
|
|
||||||
# Nix itself uses the `system` field of a derivation to decide where
|
# Nix itself uses the `system` field of a derivation to decide where
|
||||||
# to build it. This is a bit confusing for cross compilation.
|
# to build it. This is a bit confusing for cross compilation.
|
||||||
inherit (stdenv) system;
|
inherit (stdenv) hostPlatform;
|
||||||
};
|
} attrs;
|
||||||
|
|
||||||
# The meta attribute is passed in the resulting attribute set,
|
# The meta attribute is passed in the resulting attribute set,
|
||||||
# but it's not part of the actual derivation, i.e., it's not
|
# but it's not part of the actual derivation, i.e., it's not
|
||||||
|
|
|
@ -98,7 +98,18 @@ rec {
|
||||||
packagePlatforms = mapAttrs (name: value:
|
packagePlatforms = mapAttrs (name: value:
|
||||||
let res = builtins.tryEval (
|
let res = builtins.tryEval (
|
||||||
if isDerivation value then
|
if isDerivation value then
|
||||||
value.meta.hydraPlatforms or (value.meta.platforms or [ "x86_64-linux" ])
|
# TODO(@Ericson2314) deduplicate with `checkPlatform` in
|
||||||
|
# `pkgs/stdenv/generic/check-meta.nix`.
|
||||||
|
value.meta.hydraPlatforms or (let
|
||||||
|
raw = value.meta.platforms or [ "x86_64-linux" ];
|
||||||
|
toPattern = x: if builtins.isString x
|
||||||
|
then { system = x; }
|
||||||
|
else { parsed = x; };
|
||||||
|
uniform = map toPattern raw;
|
||||||
|
pred = hostPlatform:
|
||||||
|
lib.any (pat: lib.matchAttrs pat hostPlatform) uniform;
|
||||||
|
pred' = system: pred (lib.systems.elaborate { inherit system; });
|
||||||
|
in lib.filter pred' supportedSystems)
|
||||||
else if value.recurseForDerivations or false || value.recurseForRelease or false then
|
else if value.recurseForDerivations or false || value.recurseForRelease or false then
|
||||||
packagePlatforms value
|
packagePlatforms value
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue