-
-
Notifications
You must be signed in to change notification settings - Fork 17.1k
versionCheckHook: add versionCheckScript parameter #434354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes to src-cli LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few general comments:
It should target staging.
Easier to digest diff
In such cases where the changes include a new conditional branch, it'd be easier to review this if the versionCheckHook/hook.sh changes would be split to 2 commits, where the diff of the 1st of which is something like this:
diff --git c/pkgs/by-name/ve/versionCheckHook/hook.sh w/pkgs/by-name/ve/versionCheckHook/hook.sh
index 4a977fe7a888..72d1744cda66 100644
--- c/pkgs/by-name/ve/versionCheckHook/hook.sh
+++ w/pkgs/by-name/ve/versionCheckHook/hook.sh
@@ -1,15 +1,17 @@
_handleCmdOutput(){
- local command=("$1" "$2")
local versionOutput
local envArgs=()
- if [[ "$3" != "*" ]]; then
+ if [[ "$1" != "*" ]]; then
envArgs+=("--ignore-environment")
- for var in $3; do
+ for var in $1; do
envArgs+=("$var=${!var}")
done
fi
+ shift 1
+ local command=("$@")
+
versionOutput="$(env \
--chdir=/ \
--argv0="$(basename "${command[0]}")" \
@@ -38,6 +40,10 @@ versionCheckHook(){
: "${versionCheckKeepEnvironment:=}"
local cmdProgram cmdArg echoPrefix
+
+ if [[ -n "${versionCheckScript-}" ]]; then
+ echoPrefix="$(_handleCmdOutput "$versionCheckKeepEnvironment" "@bash@" "-c" "$versionCheckScript")"
+ else
if [[ ! -z "${versionCheckProgram-}" ]]; then
cmdProgram="$versionCheckProgram"
elif [[ ! -z "${NIX_MAIN_PROGRAM-}" ]]; then
@@ -62,14 +68,15 @@ versionCheckHook(){
fi
if [[ -z "${versionCheckProgramArg}" ]]; then
for cmdArg in "--help" "--version"; do
- echoPrefix="$(_handleCmdOutput "$cmdProgram" "$cmdArg" "$versionCheckKeepEnvironment")"
+ echoPrefix="$(_handleCmdOutput "$versionCheckKeepEnvironment" "$cmdProgram" "$cmdArg")"
if [[ "$echoPrefix" == "Successfully managed to" ]]; then
break
fi
done
else
cmdArg="$versionCheckProgramArg"
- echoPrefix="$(_handleCmdOutput "$cmdProgram" "$cmdArg" "$versionCheckKeepEnvironment")"
+ echoPrefix="$(_handleCmdOutput "$versionCheckKeepEnvironment" "$cmdProgram" "$cmdArg")"
+ fi
fi
if [[ "$echoPrefix" == "Did not" ]]; then
exit 2The next commit can be a pure bash formatting commit.
A different API suggestion
Do you think it'd be possible to support a simpler API for multiple arguments? I was thinking of supporting versionCheckProgramArgsArray which will take precedence over versionCheckProgramArg. I don't like how Bash is pulled there - it is too complex IMO for something which is already almost supported. BTW this would make the diff easier to digest, as you'd simply set differently the command Bash array.
|
Hey, thanks for the quick feedback!
Yes, but I think it already does?
On GitHub you can enable the "Hide whitespace" option (hidden behind the small gear icon) to make the diff more readable. Also tools like difftastic exist, but those of course require the PR to be checked out locally. I personally don't really see much value in splitting the commit this way, but if it helps reviewing this PR I will do that of course.
The problem here is that these arguments could not contain any spaces. For example Besides supporting more than one argument, another advantage of
Hm, doesn't |
Indeed that hide whitespace option makes it easier, thanks for the info 👍. I will not insist on this detail, although I personally still try to split commits like that when I think it is needed.
Are you sure it is impossible? If you could prove it for me, it'd be great. Try to create a separate setup hook that prints each element in the array, just for testing.
That's an extreme example! When I created
I couldn't help but mention that this behavior is new to me :) (#412768)
Damn what an outstanding example! I failed to reproduce that behavior even in a
diff --git a/pkgs/by-name/me/menulibre/package.nix b/pkgs/by-name/me/menulibre/package.nix
index 1a5c1d1743c3..6785cad5b6c1 100644
--- a/pkgs/by-name/me/menulibre/package.nix
+++ b/pkgs/by-name/me/menulibre/package.nix
@@ -7,9 +7,7 @@
intltool,
gobject-introspection,
wrapGAppsHook3,
- nix-update-script,
- testers,
- menulibre,
+ versionCheckHook,
writableTmpDirAsHomeHook,
}:
(1/2) Discard this hunk from worktree [y,n,q,a,d,j,J,g,/,e,?]? y
@@ -46,13 +44,8 @@ python3Packages.buildPythonApplication rec {
--replace-fail 'update_desktop_file(desktop_file, script_path)' ""
'';
- passthru = {
- updateScript = nix-update-script { };
- tests.version = testers.testVersion {
- package = menulibre;
- command = "HOME=$TMPDIR menulibre --version | cut -d' ' -f2";
- };
- };
+ nativeCheckInputs = [ versionCheckHook ];
+ doCheck = true;
meta = with lib; {
description = "Advanced menu editor with an easy-to-use interface";
Same: diff --git i/pkgs/by-name/li/lib25519/package.nix w/pkgs/by-name/li/lib25519/package.nix
index 0cd67b7b9451..68f4de0db233 100644
--- i/pkgs/by-name/li/lib25519/package.nix
+++ w/pkgs/by-name/li/lib25519/package.nix
@@ -3,7 +3,7 @@
lib,
python3,
fetchzip,
- testers,
+ versionCheckHook,
valgrind,
librandombytes,
libcpucycles,
@@ -51,19 +51,11 @@ stdenv.mkDerivation (finalAttrs: {
# failure: crypto_pow does not handle p=q overlap
doInstallCheck = !stdenv.hostPlatform.isDarwin;
- installCheckPhase = ''
- runHook preInstallCheck
- $out/bin/lib25519-test
- runHook postInstallCheck
- '';
+ nativeInstallCheckInputs = [ versionCheckHook ];
+ versionCheckProgram = "${placeholder "out"}/bin/lib25519-test";
passthru = {
updateScript = ./update.sh;
- tests.version = testers.testVersion {
- package = finalAttrs.finalPackage;
- command = "lib25519-test | head -n 2 | grep version";
- version = "lib25519 version ${finalAttrs.version}";
- };
};
meta = {Though here, it is a bit more dirty. Running the
Well I'm sorry but I wasn't clear. Technically you are right - Bash is already very abundant and it wouldn't make any difference. I mostly didn't like the way the hook is executing an external script, but let's put this discussion aside for now. To summarize, you have given a fair amount of edge cases where seemingly Although I don't think it should be needed for any program in the world, I believe that in principal our Nix - Bash interface should support arguments with spaces, and that should solve even the |
Iiuc all attributes in a
Yeah I agree, in this specific case a dedicated
That's true, however some programs include a lot more information in the
I agree that most examples I mentioned here are edge cases and that the Personally, I don't think this PR would add too much complexity to |
|
I've been working on some bash -> python conversion for hooks and here's the unsolicited WIP for this hook |
Currently the
versionCheckHookonly allows executing commands with a single argument (usually something like--version). However in some cases it is necessary to run more complex commands, e.g. with multiple arguments (see #434081 (comment) for example).This PR introduces a
versionCheckScriptparameter which can be used instead ofversionCheckProgramandversionCheckProgramArgto run an arbitrary bash command, similar to thecommandparameter intesters.testVersion.An alternative I considered was to add a
versionCheckExtraProgramArgsparameter instead which would contain a list of arguments in addition toversionCheckProgramArg. However it's not clear whether these additional arguments should appear before or after theversionCheckProgramArgand they could also not contain any spaces.Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.Add a 👍 reaction to pull requests you find important.