versionCheckHook: Default `versionCheckProgram` to `mainProgram` (#412768)

authored by philiptaron.tngl.sh and committed by GitHub befb2bee 78a2fe26

+28 -15
+1 -1
doc/hooks/versionCheckHook.section.md
··· 31 31 The variables that this phase control are: 32 32 33 33 - `dontVersionCheck`: Disable adding this hook to the [`preInstallCheckHooks`](#ssec-installCheck-phase). Useful if you do want to load the bash functions of the hook, but run them differently. 34 - - `versionCheckProgram`: The full path to the program that should print the `${version}` string. Defaults roughly to `${placeholder "out"}/bin/${pname}`. Using `$out` in the value of this variable won't work, as environment variables from this variable are not expanded by the hook. Hence using `placeholder` is unavoidable. 34 + - `versionCheckProgram`: The full path to the program that should print the `${version}` string. Defaults to using the first non-empty value `$binary` out of `${NIX_MAIN_PROGRAM}` and `${pname}`, in that order, to build roughly `${placeholder "out"}/bin/$binary`. `${NIX_MAIN_PROGRAM}`'s value comes from `meta.mainProgram`, and does not normally need to be set explicitly. When setting `versionCheckProgram`, using `$out` directly won't work, as environment variables from this variable are not expanded by the hook. Hence using `placeholder "out"` is unavoidable. 35 35 - `versionCheckProgramArg`: The argument that needs to be passed to `versionCheckProgram`. If undefined the hook tries first `--help` and then `--version`. Examples: `version`, `-V`, `-v`. 36 36 - `versionCheckKeepEnvironment`: A list of environment variables to keep and pass to the command. Only those variables should be added to this list that are actually required for the version command to work. If it is not feasible to explicitly list all these environment variables you can set this parameter to the special value `"*"` to disable the `--ignore-environment` flag and thus keep all environment variables. 37 37 - `preVersionCheck`: A hook to run before the check is done.
+5
doc/release-notes/rl-2511.section.md
··· 32 32 - `gramps` has been updated to 6.0.0 33 33 Upstream recommends [backing up your Family Trees](https://gramps-project.org/wiki/index.php/Gramps_6.0_Wiki_Manual_-_Manage_Family_Trees#Backing_up_a_Family_Tree) before upgrading. 34 34 35 + - `meta.mainProgram`: Changing this `meta` entry can lead to a package rebuild due to being used to determine the `NIX_MAIN_PROGRAM` environment variable. 36 + 37 + - `versionCheckHook`: Packages that previously relied solely on `pname` to locate the program used to version check, but have a differing `meta.mainProgram` entry, might now fail. 38 + 39 + 35 40 ## Nixpkgs Library {#sec-nixpkgs-release-25.11-lib} 36 41 37 42 <!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
+16 -10
pkgs/by-name/ve/versionCheckHook/hook.sh
··· 38 38 : "${versionCheckKeepEnvironment:=}" 39 39 40 40 local cmdProgram cmdArg echoPrefix 41 - if [[ -z "${versionCheckProgram-}" ]]; then 42 - if [[ -z "${pname-}" ]]; then 43 - echo "both \$pname and \$versionCheckProgram are empty, so" \ 44 - "we don't know which program to run the versionCheckPhase" \ 45 - "upon" >&2 46 - exit 2 47 - else 48 - cmdProgram="${!outputBin}/bin/$pname" 49 - fi 50 - else 41 + if [[ ! -z "${versionCheckProgram-}" ]]; then 51 42 cmdProgram="$versionCheckProgram" 43 + elif [[ ! -z "${NIX_MAIN_PROGRAM-}" ]]; then 44 + cmdProgram="${!outputBin}/bin/${NIX_MAIN_PROGRAM}" 45 + elif [[ ! -z "${pname-}" ]]; then 46 + echo "versionCheckHook: Package \`${pname}\` does not have the \`meta.mainProgram\` attribute." \ 47 + "We'll assume that the main program has the same name for now, but this behavior is deprecated," \ 48 + "because it leads to surprising errors when the assumption does not hold." \ 49 + "If the package has a main program, please set \`meta.mainProgram\` in its definition to make this warning go away." \ 50 + "Should the binary that outputs the intended version differ from \`meta.mainProgram\`, consider setting \`versionCheckProgram\` instead." >&2 51 + cmdProgram="${!outputBin}/bin/${pname}" 52 + else 53 + echo "versionCheckHook: \$NIX_MAIN_PROGRAM, \$versionCheckProgram and \$pname are all empty, so" \ 54 + "we don't know how to run the versionCheckPhase." \ 55 + "To fix this, set one of \`meta.mainProgram\` or \`versionCheckProgram\`." >&2 56 + exit 2 52 57 fi 58 + 53 59 if [[ ! -x "$cmdProgram" ]]; then 54 60 echo "versionCheckHook: $cmdProgram was not found, or is not an executable" >&2 55 61 exit 2
+6 -4
pkgs/stdenv/generic/make-derivation.nix
··· 716 716 ); 717 717 718 718 let 719 - envIsExportable = isAttrs env && !isDerivation env; 719 + mainProgram = meta.mainProgram or null; 720 + env' = env // lib.optionalAttrs (mainProgram != null) { NIX_MAIN_PROGRAM = mainProgram; }; 721 + envIsExportable = isAttrs env' && !isDerivation env'; 720 722 721 723 derivationArg = makeDerivationArgument ( 722 724 removeAttrs attrs ( ··· 746 748 747 749 checkedEnv = 748 750 let 749 - overlappingNames = attrNames (builtins.intersectAttrs env derivationArg); 751 + overlappingNames = attrNames (builtins.intersectAttrs env' derivationArg); 750 752 prettyPrint = lib.generators.toPretty { }; 751 753 makeError = 752 754 name: 753 - " - ${name}: in `env`: ${prettyPrint env.${name}}; in derivation arguments: ${ 755 + " - ${name}: in `env`: ${prettyPrint env'.${name}}; in derivation arguments: ${ 754 756 prettyPrint derivationArg.${name} 755 757 }"; 756 758 errors = lib.concatMapStringsSep "\n" makeError overlappingNames; ··· 764 766 assert assertMsg (isString v || isBool v || isInt v || isDerivation v) 765 767 "The `env` attribute set can only contain derivation, string, boolean or integer attributes. The `${n}` attribute is of type ${builtins.typeOf v}."; 766 768 v 767 - ) env; 769 + ) env'; 768 770 769 771 # Fixed-output derivations may not reference other paths, which means that 770 772 # for a fixed-output derivation, the corresponding inputDerivation should