From 3c781e6d191b716e0f693d6ee214f11a1ae4f832 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 24 Apr 2021 02:56:20 +0200 Subject: 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. --- pkgs/common-updater/scripts/update-source-version | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'pkgs') 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 -- cgit 1.4.1