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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maintainers/scripts/update.nix: various fixes and clean-ups #87731

Merged
merged 4 commits into from May 15, 2020

Conversation

jtojnar
Copy link
Contributor

@jtojnar jtojnar commented May 13, 2020

Motivation for this change

The packagesWith function expected an attrSet but packagesWithUpdateScript could be passing it a derivation or a list when the attribute path supplied by user through the --argstr path argument pointed to one. It only worked because derivations are also attrSets and contain their outputs as attributes, and did not work for lists at all.

Additionally, the improper handling would cause the src attribute to be built in some rare cases (mkYarnPackage seems to trigger this).

Rewriting the packagesWith function to be inductive with a derivation as a base case and attrSets and lists as inductive steps is much cleaner and also fixes the unnecessary build.

How to test this

Apply the following patch:

--- a/pkgs/desktops/gnome-3/default.nix
+++ b/pkgs/desktops/gnome-3/default.nix
@@ -27,6 +27,25 @@ lib.makeScope pkgs.newScope (self: with self; {
 
 #### Core (http://ftp.acc.umu.se/pub/GNOME/core/)
 
+  updateableBadSrc = pkgs.mkYarnPackage {
+    name = "test";
+    src = pkgs.fetchgit {
+      url = "https://example.com";
+      rev = "test";
+      sha256 = "0000000000000000000000000000000000000000000000000000000000000000";
+    };
+  };
+
+  updateableList = [
+    adwaita-icon-theme
+  ];
+
+  updateableAttrs = {
+    inherit adwaita-icon-theme;
+  };
+
+  nonUpdateable = 4;
+
   adwaita-icon-theme = callPackage ./core/adwaita-icon-theme { };
 
   baobab = callPackage ./core/baobab { };

and run:

nix-shell maintainers/scripts/update.nix --argstr path gnome3.updateableBadSrc
nix-shell maintainers/scripts/update.nix --argstr path gnome3.updateableList
nix-shell maintainers/scripts/update.nix --argstr path gnome3.updateableAttrs
nix-shell maintainers/scripts/update.nix --argstr path gnome3.nonUpdateable

None of these should fail or try to download their sources.

This will make it easier to change it if we want to decouple from pkgs.
It does not make sense to look for derivations within derivations,
not even when `recurseForDerivations` is true. Nix does not do that either:

https://github.com/NixOS/nix/blob/ebc024df2287085d48ed6194aa756fd70c07f76c/src/libexpr/get-drvs.cc#L346-L355
The `packagesWith` function expected an attrSet but `packagesWithUpdateScript`
could be passing it a derivation or a list when the attribute path
supplied by user through the `--argstr path` argument pointed to one.
It only worked because derivations are also attrSets and contain their
outputs as attributes, and did not work for lists at all.

Additionally, the improper handling would cause the `src` attribute
to be built in some rare cases (`mkYarnPackage` seems to trigger this).

Rewriting the `packagesWith` function to be inductive with a derivation
as a base case and attrSets and lists as inductive steps is much cleaner
and also fixes the unnecessary build.
@jtojnar jtojnar requested a review from edolstra as a code owner May 13, 2020 12:17
@jtojnar jtojnar requested a review from garbas May 13, 2020 16:46
@jtojnar jtojnar merged commit a762c0e into NixOS:master May 15, 2020
@jtojnar jtojnar deleted the update-no-build-src branch May 15, 2020 13:40
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

1 participant