Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdenv: re-add meta.repository (resurrected) #301947

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lolbinarycat
Copy link
Contributor

Description of changes

previous PR (#300313) got messed up due to me trying to do too many fancy git things at once (mainly using shallow pulls and amending commits)

i've updated the documentation to match the new behavior, and have added a different example

@a-n-n-a-l-e-e @AndersonTorres @nyabinary for participating in the previous PR

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 馃憤 reaction to pull requests you find important.

Copy link
Member

@rhendric rhendric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with its predecessor, I think the design of this (not any particular line of code in this PR, but the dependency of meta on src) needs to be discussed more before this PR is merged. I'll withdraw my objection if it is discussed and I'm outvoted or convinced otherwise, but there's no need for haste here. We should take the time to hash it out in #293838.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/when-should-meta-attributes-be-computed/42833/1

@@ -454,6 +464,15 @@ let
hasOutput = out: builtins.elem out outputs;
in
{
# get the default value for the meta.repository field.
# the fetchFrom* fetchers set src.meta.homepage
# NOTE: this will fail if src fails to eval, in that case either set meta.repository manually to prevent this default from being evaluated, or just make sure src doesn't fail to eval.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried builtins.tryEval to catch the src evaluation errors and just put nothing in it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

builtins.tryEval only catches throw errors. this note was orignally made when packages enconering abort-class errors in src was fairly common (at the time this was causing eval to fail), although both of these issues have been fixed since then.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abort-class errors in evaluations are abnormal. Throwing in derivations is the only thing allowed to make evaluation fail.

Doing src = { "x86_64-linux" = ...; }.${builtins.currentSystem} is a mistake in nixpkgs, it requires at least:
src = { ... }.${builtins.currentSystem} or (throw "Source not available on {...}")

Thus, tryEval is the only thing you really really need in checkMeta for infaillible evaluations, all the other errors are bugs in nixpkgs and must be fixed as such because Hydra won't catch them neither.

Copy link
Member

@RaitoBezarius RaitoBezarius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the approach makes sense, I would try to see if builtins.tryEval is usable and has no performance impact.

Comment on lines 13 to 15
findFirst
filter
head
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
findFirst
filter
head
filter
findFirst
head

@ghost
Copy link

ghost commented Apr 9, 2024

I think the approach makes sense, I would try to see if builtins.tryEval is usable and has no performance impact.

wrapping in builtins.tryEval has a negligible performance impact, so should be added IMO.

median of 11 runs (only really matters for cpu time, everything else is stable i think).

using change 253c0db and x86_64-linux check meta tests

baseline is change 253c0db, prlist11 is with this PR, prlist15 and prlist16 use tryEval

name baseline prlist11 / baseline prlist15 / baseline prlist16 / baseline
cpuTime 127.11 0.9885 0.9994 1.0034
envs.bytes 6551424928.0 1.0011 1.0013 1.0013
envs.elements 344611966.0 1.0011 1.0013 1.0013
envs.number 237158075.0 1.0011 1.0013 1.0013
gc.heapSize 19734130688.0 1.0 0.9991 0.9991
gc.totalBytes 40074163200.0 1.0019 1.0022 1.0022
list.bytes 767523792.0 1.0001 1.0001 1.0001
list.concats 17306647.0 1.0 1.0 1.0
list.elements 95940474.0 1.0001 1.0001 1.0001
nrAvoided 274572669.0 1.001 1.001 1.001
nrFunctionCalls 218766710.0 1.001 1.001 1.0013
nrLookups 109634172.0 1.0039 1.0058 1.0058
nrOpUpdateValuesCopied 606519203.0 1.0012 1.0012 1.0012
nrOpUpdates 2766490.0 1.0055 1.0055 1.0055
nrPrimOpCalls 122442293.0 1.0007 1.0013 1.0013
nrThunks 334642079.0 1.0024 1.0028 1.0028
sets.bytes 13762198032.0 1.0022 1.0024 1.0024
sets.elements 809415832.0 1.0019 1.0021 1.0021
sets.number 50721545.0 1.0066 1.008 1.008
sizes.Attr 16.0 1.0 1.0 1.0
sizes.Bindings 16.0 1.0 1.0 1.0
sizes.Env 16.0 1.0 1.0 1.0
sizes.Value 24.0 1.0 1.0 1.0
symbols.bytes 2341038.0 1.0 1.0 1.0
symbols.number 168577.0 1.0 1.0 1.0
values.bytes 10281315384.0 1.0023 1.0028 1.0028
values.number 428388141.0 1.0023 1.0028 1.0028
name geomean
prlist11 1.0009
prlist15 1.0015
prlist16 1.0017

then running with (<pkg>.meta.repository or null) for all x64-linux packages also has negligible performance impact.
baseline is this PR, prlist15 and prlist16 are variations of tryEval

NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH=results/baseline-stats$i.json nix eval -f - --show-trace <<EOF
with import ./.{}; ((import ./out-paths.nix) pkgs)
EOF
name baseline prlist15 / baseline prlist16 / baseline
cpuTime 18.26 1.0004 1.0042
envs.bytes 1031048184.0 1.0015 1.0015
envs.elements 60505417.0 1.0011 1.0011
envs.number 34187803.0 1.0019 1.0019
gc.heapSize 4699906048.0 0.9786 0.9786
gc.totalBytes 7549011504.0 1.0015 1.0015
list.bytes 84133128.0 1.0 1.0
list.concats 1534723.0 1.0 1.0
list.elements 10516641.0 1.0 1.0
nrAvoided 3836174.0 1.0 1.0
nrFunctionCalls 29846130.0 1.0 1.0022
nrLookups 17079015.0 1.0113 1.0113
nrOpUpdateValuesCopied 137632128.0 1.0 1.0
nrOpUpdates 6493171.0 1.0 1.0
nrPrimOpCalls 12235438.0 1.0053 1.0053
nrThunks 61452402.0 1.0021 1.0021
sets.bytes 3186938304.0 1.001 1.001
sets.elements 186209984.0 1.0007 1.0007
sets.number 12973660.0 1.005 1.005
sizes.Attr 16.0 1.0 1.0
sizes.Bindings 16.0 1.0 1.0
sizes.Env 16.0 1.0 1.0
sizes.Value 24.0 1.0 1.0
symbols.bytes 1662469.0 1.0 1.0
symbols.number 128122.0 1.0 1.0
values.bytes 1908011976.0 1.0024 1.0024
values.number 7950049.0 1.0024 1.0024
name geomean
prlist15 1.0005
prlist16 1.0008
prlist11.diff
diff --git a/pkgs/stdenv/generic/check-meta.nix b/pkgs/stdenv/generic/check-meta.nix
index 1cd1ae6dd72e..f1f486b115a8 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
@@ -39,6 +41,11 @@ let
     toPretty
   ;
 
+  unlist = list:
+  if length list == 1
+  then head list
+  else list;
+
   # If we're in hydra, we can dispense with the more verbose error
   # messages and make problems easier to spot.
   inHydra = config.inHydra or false;
@@ -303,6 +310,10 @@ let
       (listOf str)
       str
     ];
+    repository = union [
+      (listOf str)
+      str
+    ];
     downloadPage = str;
     changelog = union [
       (listOf str)
@@ -452,8 +463,14 @@ let
     let
       outputs = attrs.outputs or [ "out" ];
       hasOutput = out: builtins.elem out outputs;
-    in
-    {
+    in {
+      repository =
+        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.
prlist15.diff
diff --git a/pkgs/stdenv/generic/check-meta.nix b/pkgs/stdenv/generic/check-meta.nix
index bcb2ca249ddf..18764e52a319 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
@@ -39,6 +41,11 @@ let
     toPretty
   ;
 
+  unlist = list:
+  if length list == 1
+  then head list
+  else list;
+
   # If we're in hydra, we can dispense with the more verbose error
   # messages and make problems easier to spot.
   inHydra = config.inHydra or false;
@@ -303,6 +310,10 @@ let
       (listOf str)
       str
     ];
+    repository = union [
+      (listOf str)
+      str
+    ];
     downloadPage = str;
     changelog = union [
       (listOf str)
@@ -454,8 +465,15 @@ let
     let
       outputs = attrs.outputs or [ "out" ];
       hasOutput = out: builtins.elem out outputs;
-    in
-    {
+    in {
+      repository = let res = 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 []);
+        in if res.success then res.value else [];
+
       # `name` derivation attribute includes cross-compilation cruft,
       # is under assert, and is sanitized.
       # Let's have a clean always accessible version here.
prlist16.diff
diff --git a/pkgs/stdenv/generic/check-meta.nix b/pkgs/stdenv/generic/check-meta.nix
index bcb2ca249ddf..a31c02ec225c 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
@@ -39,6 +41,16 @@ let
     toPretty
   ;
 
+  unlist = list:
+  if length list == 1
+  then head list
+  else list;
+
+  valOrEmpty = res:
+  if res.success
+  then res.value
+  else [];
+
   # If we're in hydra, we can dispense with the more verbose error
   # messages and make problems easier to spot.
   inHydra = config.inHydra or false;
@@ -303,6 +315,10 @@ let
       (listOf str)
       str
     ];
+    repository = union [
+      (listOf str)
+      str
+    ];
     downloadPage = str;
     changelog = union [
       (listOf str)
@@ -454,8 +470,14 @@ let
     let
       outputs = attrs.outputs or [ "out" ];
       hasOutput = out: builtins.elem out outputs;
-    in
-    {
+    in {
+      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.

@lolbinarycat
Copy link
Contributor Author

added tryEval and fixed alphabetization of imports.

@rhendric rhendric self-requested a review April 9, 2024 20:21
rhendric

This comment was marked as duplicate.

@rhendric rhendric dismissed their stale review April 9, 2024 20:22

I still don't endorse this design but Raito's approval is sufficient for me to get out of the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants