summary refs log tree commit diff
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2020-09-20 00:20:34 +0200
committerJan Tojnar <jtojnar@gmail.com>2020-09-20 20:11:46 +0200
commitc21a85c6a08df971b49adba13428abcf71097e41 (patch)
treeabe187419523328058e6f574a8c4139774bb9997
parentb351de0971619d0bd21b347401fa3e4815bae8be (diff)
downloadnixpkgs-c21a85c6a08df971b49adba13428abcf71097e41.tar
nixpkgs-c21a85c6a08df971b49adba13428abcf71097e41.tar.gz
nixpkgs-c21a85c6a08df971b49adba13428abcf71097e41.tar.bz2
nixpkgs-c21a85c6a08df971b49adba13428abcf71097e41.tar.lz
nixpkgs-c21a85c6a08df971b49adba13428abcf71097e41.tar.xz
nixpkgs-c21a85c6a08df971b49adba13428abcf71097e41.tar.zst
nixpkgs-c21a85c6a08df971b49adba13428abcf71097e41.zip
maintainers/scripts/update.nix: auto-detect attrPath
-rw-r--r--doc/stdenv/stdenv.xml2
-rwxr-xr-xmaintainers/scripts/update.nix53
-rw-r--r--maintainers/scripts/update.py4
-rw-r--r--pkgs/desktops/gnome-3/update.nix5
4 files changed, 32 insertions, 32 deletions
diff --git a/doc/stdenv/stdenv.xml b/doc/stdenv/stdenv.xml
index 2a148a9c2a1..6962c57a6ac 100644
--- a/doc/stdenv/stdenv.xml
+++ b/doc/stdenv/stdenv.xml
@@ -490,7 +490,7 @@ passthru.updateScript = {
       </note>
      </para>
      <para>
-       <filename>maintainers/scripts/update.nix</filename> also supports automatically creating commits by running it with <literal>--argstr commit true</literal> but it requires either declaring the <variable>attrPath</variable>, or adding a <literal>commit</literal> to <variable>supportedFeatures</variable> and <link xlink:href="#var-passthru-updateScript-commit">modifying the script accordingly</link>.
+       <filename>maintainers/scripts/update.nix</filename> also supports automatically creating commits by running it with <literal>--argstr commit true</literal>. Neither declaring the <variable>attrPath</variable> attribute, or adding a <literal>commit</literal> to <variable>supportedFeatures</variable> and <link xlink:href="#var-passthru-updateScript-commit">modifying the script accordingly</link> is required. It might be useful if you want to customize the values to something else than what <filename>update.nix</filename> detects.
      </para>
      <variablelist>
       <title>Supported features</title>
diff --git a/maintainers/scripts/update.nix b/maintainers/scripts/update.nix
index 3d6f3500f5c..c60860629a9 100755
--- a/maintainers/scripts/update.nix
+++ b/maintainers/scripts/update.nix
@@ -32,27 +32,31 @@ let
       in
         [x] ++ nubOn f xs;
 
-  packagesWithPath = relativePath: cond: return: pathContent:
+  packagesWithPath = rootPath: cond: pkgs:
     let
-      result = builtins.tryEval pathContent;
-
-      dedupResults = lst: nubOn (pkg: pkg.updateScript) (lib.concatLists lst);
-    in
-      if result.success then
+      packagesWithPathInner = relativePath: pathContent:
         let
-          pathContent = result.value;
+          result = builtins.tryEval pathContent;
+
+          dedupResults = lst: nubOn ({ package, attrPath }: package.updateScript) (lib.concatLists lst);
         in
-          if lib.isDerivation pathContent then
-            lib.optional (cond relativePath pathContent) (return relativePath pathContent)
-          else if lib.isAttrs pathContent then
-            # If user explicitly points to an attrSet or it is marked for recursion, we recur.
-            if relativePath == [] || pathContent.recurseForDerivations or false || pathContent.recurseForRelease or false then
-              dedupResults (lib.mapAttrsToList (name: elem: packagesWithPath (relativePath ++ [name]) cond return elem) pathContent)
-            else []
-          else if lib.isList pathContent then
-            dedupResults (lib.imap0 (i: elem: packagesWithPath (relativePath ++ [i]) cond return elem) pathContent)
-          else []
-      else [];
+          if result.success then
+            let
+              pathContent = result.value;
+            in
+              if lib.isDerivation pathContent then
+                lib.optional (cond relativePath pathContent) { attrPath = lib.concatStringsSep "." relativePath; package = pathContent; }
+              else if lib.isAttrs pathContent then
+                # If user explicitly points to an attrSet or it is marked for recursion, we recur.
+                if relativePath == rootPath || pathContent.recurseForDerivations or false || pathContent.recurseForRelease or false then
+                  dedupResults (lib.mapAttrsToList (name: elem: packagesWithPathInner (relativePath ++ [name]) elem) pathContent)
+                else []
+              else if lib.isList pathContent then
+                dedupResults (lib.imap0 (i: elem: packagesWithPathInner (relativePath ++ [i]) elem) pathContent)
+              else []
+          else [];
+    in
+      packagesWithPathInner rootPath pkgs;
 
   packagesWith = packagesWithPath [];
 
@@ -73,18 +77,17 @@ let
                                    else false
                                  )
                    )
-                   (relativePath: pkg: pkg)
                    pkgs;
 
   packagesWithUpdateScript = path:
     let
-      pathContent = lib.attrByPath (lib.splitString "." path) null pkgs;
+      prefix = lib.splitString "." path;
+      pathContent = lib.attrByPath prefix null pkgs;
     in
       if pathContent == null then
         builtins.throw "Attribute path `${path}` does not exists."
       else
-        packagesWith (relativePath: pkg: builtins.hasAttr "updateScript" pkg)
-                       (relativePath: pkg: pkg)
+        packagesWithPath prefix (relativePath: pkg: builtins.hasAttr "updateScript" pkg)
                        pathContent;
 
   packageByName = name:
@@ -96,7 +99,7 @@ let
       else if ! builtins.hasAttr "updateScript" package then
         builtins.throw "Package with an attribute name `${name}` does not have a `passthru.updateScript` attribute defined."
       else
-        package;
+        { attrPath = name; inherit package; };
 
   packages =
     if package != null then
@@ -140,13 +143,13 @@ let
         --argstr commit true
   '';
 
-  packageData = package: {
+  packageData = { package, attrPath }: {
     name = package.name;
     pname = lib.getName package;
     oldVersion = lib.getVersion package;
     updateScript = map builtins.toString (lib.toList (package.updateScript.command or package.updateScript));
     supportedFeatures = package.updateScript.supportedFeatures or [];
-    attrPath = package.updateScript.attrPath or null;
+    attrPath = package.updateScript.attrPath or attrPath;
   };
 
   packagesJson = pkgs.writeText "packages.json" (builtins.toJSON (map packageData packages));
diff --git a/maintainers/scripts/update.py b/maintainers/scripts/update.py
index 373818d303b..61387ee8cb3 100644
--- a/maintainers/scripts/update.py
+++ b/maintainers/scripts/update.py
@@ -91,8 +91,8 @@ async def check_changes(package: Dict, worktree: str, update_info: str):
     if len(changes) == 1:
         # Dynamic data from updater take precedence over static data from passthru.updateScript.
         if 'attrPath' not in changes[0]:
-            if 'attrPath' in package:
-                changes[0]['attrPath'] = package['attrPath']
+            # update.nix is always passing attrPath
+            changes[0]['attrPath'] = package['attrPath']
 
         if 'oldVersion' not in changes[0]:
             # update.nix is always passing oldVersion
diff --git a/pkgs/desktops/gnome-3/update.nix b/pkgs/desktops/gnome-3/update.nix
index 5c3e5c24785..1bceddf77eb 100644
--- a/pkgs/desktops/gnome-3/update.nix
+++ b/pkgs/desktops/gnome-3/update.nix
@@ -23,7 +23,4 @@ let
     latest_tag=$(python "${./find-latest-version.py}" "$package_name" "$version_policy" "stable" ${upperBoundFlag})
     update-source-version "$attr_path" "$latest_tag"
   '';
-in {
-  command = [ updateScript packageName attrPath versionPolicy ];
-  inherit attrPath;
-}
+in [ updateScript packageName attrPath versionPolicy ]