diff options
author | Jan Tojnar <jtojnar@gmail.com> | 2021-04-24 02:56:20 +0200 |
---|---|---|
committer | Jan Tojnar <jtojnar@gmail.com> | 2021-04-24 03:41:33 +0200 |
commit | 3c781e6d191b716e0f693d6ee214f11a1ae4f832 (patch) | |
tree | 26c95c551fdb02f38de30f7094f750e7614e50c9 /pkgs/common-updater/scripts | |
parent | d788c091b6348dd897c438a1ec2ad40822170e3c (diff) |
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/scripts')
-rwxr-xr-x | pkgs/common-updater/scripts/update-source-version | 9 |
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 831f65e4d90d..0c914ebee2c4 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 |