summary refs log tree commit diff
path: root/pkgs/common-updater
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2021-04-24 04:36:58 +0200
committerJan Tojnar <jtojnar@gmail.com>2021-04-24 04:52:48 +0200
commit3771de8ae019afbf0d37ffe390f3fec92cd2dffd (patch)
tree2127f7ee6f85b44fccf98161018dfb943fdfd7fd /pkgs/common-updater
parent38e20a3242a8dbd50d1c7d2dc060232edb7d907f (diff)
downloadnixpkgs-3771de8ae019afbf0d37ffe390f3fec92cd2dffd.tar
nixpkgs-3771de8ae019afbf0d37ffe390f3fec92cd2dffd.tar.gz
nixpkgs-3771de8ae019afbf0d37ffe390f3fec92cd2dffd.tar.bz2
nixpkgs-3771de8ae019afbf0d37ffe390f3fec92cd2dffd.tar.lz
nixpkgs-3771de8ae019afbf0d37ffe390f3fec92cd2dffd.tar.xz
nixpkgs-3771de8ae019afbf0d37ffe390f3fec92cd2dffd.tar.zst
nixpkgs-3771de8ae019afbf0d37ffe390f3fec92cd2dffd.zip
common-updater-scripts: Support attribute lookup in flake
In flakes, packages are not exposed directly but instead they are declared
inside “packages” or “legacyPackages” output under their host platform.
flake-compat reflects this.

Let’s look for an attribute also in these outputs if the direct lookup fails.
Diffstat (limited to 'pkgs/common-updater')
-rwxr-xr-xpkgs/common-updater/scripts/update-source-version21
1 files changed, 21 insertions, 0 deletions
diff --git a/pkgs/common-updater/scripts/update-source-version b/pkgs/common-updater/scripts/update-source-version
index 15792e1502e..d5c23466ee0 100755
--- a/pkgs/common-updater/scripts/update-source-version
+++ b/pkgs/common-updater/scripts/update-source-version
@@ -19,6 +19,7 @@ args=()
 for arg in "$@"; do
     case $arg in
         --system=*)
+            system="${arg#*=}"
             systemArg="--system ${arg#*=}"
         ;;
         --version-key=*)
@@ -78,6 +79,26 @@ if [[ -z "$versionKey" ]]; then
     versionKey=version
 fi
 
+# Allow finding packages among flake outputs in repos using flake-compat.
+pname=$(nix-instantiate $systemArg --eval --strict -A "$attr.name" || echo)
+if [[ -z "$pname" ]]; then
+    if [[ -z "$system" ]]; then
+        system=$(nix-instantiate --eval -E 'builtins.currentSystem' | tr -d '"')
+    fi
+
+    pname=$(nix-instantiate $systemArg --eval --strict -A "packages.$system.$attr.name" || echo)
+    if [[ -n "$pname" ]]; then
+        attr="packages.$system.$attr"
+    else
+        pname=$(nix-instantiate $systemArg --eval --strict -A "legacyPackages.$system.$attr.name" || echo)
+        if [[ -n "$pname" ]]; then
+            attr="legacyPackages.$system.$attr"
+        else
+            die "Could not find attribute '$attr'!"
+        fi
+    fi
+fi
+
 if [[ -z "$nixFile" ]]; then
     nixFile=$(nix-instantiate $systemArg --eval --strict -A "$attr.meta.position" | sed -re 's/^"(.*):[0-9]+"$/\1/')
     if [[ ! -f "$nixFile" ]]; then