diff --git a/doc/stdenv/meta.chapter.md b/doc/stdenv/meta.chapter.md index 7f57eda791ea0..ae10d91e34de0 100644 --- a/doc/stdenv/meta.chapter.md +++ b/doc/stdenv/meta.chapter.md @@ -47,6 +47,10 @@ Release branch. Used to specify that a package is not going to receive updates t The package’s homepage. Example: `https://www.gnu.org/software/hello/manual/` +### `repository` {#var-meta-repository} + +A webpage (or list of webpages) where the package's source code can be viewed. `https` links are preferred if available. Automatically set to a default value if the package uses a `fetchFrom*` fetcher for its `src`. Example: `https://gitlab.freedesktop.org/libfprint/fprintd/` + ### `downloadPage` {#var-meta-downloadPage} The page where a link to the current version can be found. Example: `https://ftp.gnu.org/gnu/hello/` diff --git a/pkgs/stdenv/generic/check-meta.nix b/pkgs/stdenv/generic/check-meta.nix index 1cd1ae6dd72e4..5b96265543bee 100644 --- a/pkgs/stdenv/generic/check-meta.nix +++ b/pkgs/stdenv/generic/check-meta.nix @@ -10,7 +10,9 @@ let concatMapStrings concatMapStringsSep concatStrings + filter findFirst + head isDerivation length concatMap @@ -303,6 +305,10 @@ let (listOf str) str ]; + repository = union [ + (listOf str) + str + ]; downloadPage = str; changelog = union [ (listOf str) @@ -440,6 +446,15 @@ let # ----- else { valid = "yes"; }); + unlist = list: + if length list == 1 + then head list + else list; + + valOrEmpty = res: + if res.success + then res.value + else []; # The meta attribute is passed in the resulting attribute set, # but it's not part of the actual derivation, i.e., it's not @@ -454,6 +469,17 @@ let hasOutput = out: builtins.elem out outputs; in { + # get the default value for the meta.repository field. + # the fetchFrom* fetchers set src.meta.homepage + # tryEval will catch any throw-class errors, abort-class errors during + # evaluation are bugs and should be fixed. + repository = + valOrEmpty (builtins.tryEval ( + if attrs ? src.meta.homepage + then attrs.src.meta.homepage + else if attrs ? srcs && isList attrs.srcs + then unlist (map (src: src.meta.homepage) (filter (src: src ? meta.homepage) attrs.srcs)) + else [])); # `name` derivation attribute includes cross-compilation cruft, # is under assert, and is sanitized. # Let's have a clean always accessible version here.