summary refs log tree commit diff
path: root/pkgs/common-updater
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2021-04-24 02:56:20 +0200
committerJan Tojnar <jtojnar@gmail.com>2021-04-24 03:41:33 +0200
commit3c781e6d191b716e0f693d6ee214f11a1ae4f832 (patch)
tree26c95c551fdb02f38de30f7094f750e7614e50c9 /pkgs/common-updater
parentd788c091b6348dd897c438a1ec2ad40822170e3c (diff)
downloadnixpkgs-3c781e6d191b716e0f693d6ee214f11a1ae4f832.tar
nixpkgs-3c781e6d191b716e0f693d6ee214f11a1ae4f832.tar.gz
nixpkgs-3c781e6d191b716e0f693d6ee214f11a1ae4f832.tar.bz2
nixpkgs-3c781e6d191b716e0f693d6ee214f11a1ae4f832.tar.lz
nixpkgs-3c781e6d191b716e0f693d6ee214f11a1ae4f832.tar.xz
nixpkgs-3c781e6d191b716e0f693d6ee214f11a1ae4f832.tar.zst
nixpkgs-3c781e6d191b716e0f693d6ee214f11a1ae4f832.zip
common-updater-scripts: handle default.nix without arguments
So that the script can be used outside of nixpkgs.
For example, the default.nix recommended by flake-compat does not take arguments.
Diffstat (limited to 'pkgs/common-updater')
-rwxr-xr-xpkgs/common-updater/scripts/update-source-version9
1 files changed, 6 insertions, 3 deletions
diff --git a/pkgs/common-updater/scripts/update-source-version b/pkgs/common-updater/scripts/update-source-version
index 831f65e4d90..0c914ebee2c 100755
--- a/pkgs/common-updater/scripts/update-source-version
+++ b/pkgs/common-updater/scripts/update-source-version
@@ -59,6 +59,9 @@ newVersion=${args[1]}
 newHash=${args[2]}
 newUrl=${args[3]}
 
+# Third-party repositories might not accept arguments in their default.nix.
+importTree="(let tree = import ./.; in if builtins.isFunction tree then tree {} else tree)"
+
 if (( "${#args[*]}" < 2 )); then
     echo "$scriptName: Too few arguments"
     usage
@@ -93,13 +96,13 @@ if [[ $(grep --count "$oldHash" "$nixFile") != 1 ]]; then
     die "Couldn't locate old source hash '$oldHash' (or it appeared more than once) in '$nixFile'!"
 fi
 
-oldUrl=$(nix-instantiate $systemArg --eval -E "with import ./. {}; builtins.elemAt ($attr.src.drvAttrs.urls or [ $attr.src.url ]) 0" | tr -d '"')
+oldUrl=$(nix-instantiate $systemArg --eval -E "with $importTree; builtins.elemAt ($attr.src.drvAttrs.urls or [ $attr.src.url ]) 0" | tr -d '"')
 
 if [[ -z "$oldUrl" ]]; then
     die "Couldn't evaluate source url from '$attr.src'!"
 fi
 
-oldVersion=$(nix-instantiate $systemArg --eval -E "with import ./. {}; $attr.${versionKey} or (builtins.parseDrvName $attr.name).version" | tr -d '"')
+oldVersion=$(nix-instantiate $systemArg --eval -E "with $importTree; $attr.${versionKey} or (builtins.parseDrvName $attr.name).version" | tr -d '"')
 
 if [[ -z "$oldVersion" ]]; then
     die "Couldn't find out the old version of '$attr'!"
@@ -114,7 +117,7 @@ if [[ "$oldVersion" = "$newVersion" ]]; then
 fi
 
 if [[ -n "$newRevision" ]]; then
-    oldRevision=$(nix-instantiate $systemArg --eval -E "with import ./. {}; $attr.src.rev" | tr -d '"')
+    oldRevision=$(nix-instantiate $systemArg --eval -E "with $importTree; $attr.src.rev" | tr -d '"')
     if [[ -z "$oldRevision" ]]; then
         die "Couldn't evaluate source revision from '$attr.src'!"
     fi