stdenv: factor out meta attr augmentation for reusability

stdenv: check if separating commonMeta from assertValidity fixes laziness issue

```
error: cannot coerce null to a string

at /var/lib/ofborg/checkout/repo/38dca4e3aa6bca43ea96d2fcc04e8229/mr-est/ofborg-evaluator-3/pkgs/development/coq-modules/coq-lsp/default.nix:34:60:

    33|     homepage = "https://github.com/ejgallego/coq-lsp";
    34|     changelog = "https://github.com/ejgallego/coq-lsp/blob/${defaultVersion}/CHANGES.md";
```
This commit is contained in:
Emily Trau 2023-04-26 13:43:44 +10:00 committed by Artturin
parent e852acf2f0
commit 2ad68a7d90
2 changed files with 55 additions and 42 deletions

View File

@ -390,6 +390,55 @@ let
# -----
else { valid = "yes"; });
# The meta attribute is passed in the resulting attribute set,
# but it's not part of the actual derivation, i.e., it's not
# passed to the builder and is not a dependency. But since we
# include it in the result, it *is* available to nix-env for queries.
# Example:
# meta = checkMeta.commonMeta { inherit validity attrs pos references; };
# validity = checkMeta.assertValidity { inherit meta attrs; };
commonMeta = { validity, attrs, pos ? null, references ? [ ] }:
let
outputs = attrs.outputs or [ "out" ];
in
{
# `name` derivation attribute includes cross-compilation cruft,
# is under assert, and is sanitized.
# Let's have a clean always accessible version here.
name = attrs.name or "${attrs.pname}-${attrs.version}";
# If the packager hasn't specified `outputsToInstall`, choose a default,
# which is the name of `p.bin or p.out or p` along with `p.man` when
# present.
#
# If the packager has specified it, it will be overridden below in
# `// meta`.
#
# Note: This default probably shouldn't be globally configurable.
# Services and users should specify outputs explicitly,
# unless they are comfortable with this default.
outputsToInstall =
let
hasOutput = out: builtins.elem out outputs;
in
[ (lib.findFirst hasOutput null ([ "bin" "out" ] ++ outputs)) ]
++ lib.optional (hasOutput "man") "man";
}
// attrs.meta or { }
# Fill `meta.position` to identify the source location of the package.
// lib.optionalAttrs (pos != null) {
position = pos.file + ":" + toString pos.line;
} // {
# Expose the result of the checks for everyone to see.
inherit (validity) unfree broken unsupported insecure;
available = validity.valid != "no"
&& (if config.checkMetaRecursively or false
then lib.all (d: d.meta.available or true) references
else true);
};
assertValidity = { meta, attrs }: let
validity = checkValidity attrs;
in validity // {
@ -401,6 +450,7 @@ let
warn = handleEvalWarning { inherit meta attrs; } { inherit (validity) reason errormsg; };
yes = true;
}.${validity.valid};
};
in assertValidity
in { inherit assertValidity commonMeta; }

View File

@ -501,46 +501,8 @@ else let
lib.mapNullable unsafeDerivationToUntrackedOutpath attrs.allowedRequisites;
};
validity = checkMeta { inherit meta attrs; };
# The meta attribute is passed in the resulting attribute set,
# but it's not part of the actual derivation, i.e., it's not
# passed to the builder and is not a dependency. But since we
# include it in the result, it *is* available to nix-env for queries.
meta = {
# `name` above includes cross-compilation cruft,
# is under assert, and is sanitized.
# Let's have a clean always accessible version here.
name = attrs.name or "${attrs.pname}-${attrs.version}";
# If the packager hasn't specified `outputsToInstall`, choose a default,
# which is the name of `p.bin or p.out or p` along with `p.man` when
# present.
#
# If the packager has specified it, it will be overridden below in
# `// meta`.
#
# Note: This default probably shouldn't be globally configurable.
# Services and users should specify outputs explicitly,
# unless they are comfortable with this default.
outputsToInstall =
let
hasOutput = out: builtins.elem out outputs;
in [( lib.findFirst hasOutput null (["bin" "out"] ++ outputs) )]
++ lib.optional (hasOutput "man") "man";
}
// attrs.meta or {}
# Fill `meta.position` to identify the source location of the package.
// lib.optionalAttrs (pos != null) {
position = pos.file + ":" + toString pos.line;
} // {
# Expose the result of the checks for everyone to see.
inherit (validity) unfree broken unsupported insecure;
available = validity.valid != "no"
&& (if config.checkMetaRecursively or false
then lib.all (d: d.meta.available or true) references
else true);
};
meta = checkMeta.commonMeta { inherit validity attrs pos references; };
validity = checkMeta.assertValidity { inherit meta attrs; };
checkedEnv =
let
@ -591,7 +553,8 @@ lib.extendDerivation
disallowedRequisites = [ ];
});
inherit meta passthru overrideAttrs;
inherit passthru overrideAttrs;
inherit meta;
} //
# Pass through extra attributes that are not inputs, but
# should be made available to Nix expressions using the