-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
Tracking: deprecate sha256 attribute in fetchers in favor of hash = "<SRI hash>" #325892
Comments
You can still use the SRI sha256 hash in the |
(Taking the opportunity to plug the related |
Yes, it's like |
Anyway, discussing strategy: should we remove the usages first for a given fetcher, before we add the warnings? And your example bash script, it may work safely for something like |
Yes, otherwise ofBorg will fail?
I'm adding one more grep like |
(Thank you, I had no idea |
I didn't know borgo fails on warnings. But anyway I meant, keeping the 0-rebuild treewide in a separate PR would make it easier to avoid merge conflicts and mixing of logical changes.
Some packages have multiple fetcher or people doing some custom constructs in the same file, which is why I'll try to avoid grep in this way if possible. |
There are many fetchers that are based on others( |
So I wrote this script: my script#!/usr/bin/env bash
EDITED_LOG=./edited-log
PROBLEM_LOG=./problem-log
SEARCH_CACHE=./search-cache
mkfifo nix_repl_in
mkfifo nix_repl_out
trap "rm -f nix_repl_in nix_repl_out" EXIT
# if replacing more files we can remove 2>/dev/null
nix repl < nix_repl_in > nix_repl_out 2>/dev/null &
NIX_REPL_PID=$!
sleep 2
exec 13>nix_repl_in
exec 14< nix_repl_out
extract_output() {
output=$(echo $1 | ansi2txt)
if [[ $output == "\"\"" ]]; then
return 1
elif [[ $output =~ ^\"([^\"]+)\"$ ]]; then
echo "${BASH_REMATCH[1]}"
elif [[ $output == "null" ]]; then
echo "null"
else
return 1
fi
}
send_repl() {
local cmd=$1
echo "$cmd" >&13
echo "$cmd" > ./repl_in
while IFS= read -r -d $'\n' line <&14; do
if [[ -z "$line" ]]; then
return 1
else
echo "$(extract_output $line)"
echo "$line" > ./repl_out
fi
done
}
replace_hash() {
local attr_name=$1
local hashAlgo=$(send_repl "${attr_name}.src.outputHashAlgo") || return 1
# Only to limit scope here, can be adjusted
local hashHomepage=$(send_repl "${attr_name}.src.meta.homepage") || return 1
if [[ "$hashAlgo" == "sha256" ]] && [[ "$hashHomepage" == "https://gitlab.com/"* ]]; then
local hash=$(send_repl "${attr_name}.src.outputHash") || return 1
# echo "$attr_name hash"
if [[ "$hash" == "sha256"* ]]; then
local position=$(send_repl "${attr_name}.meta.position") || return 1
[[ $position == "null" ]] && return 1
local position_file=${position%%:*}
grep -q "sha256 = \"$hash\"" $position_file
if [ $? -eq 0 ]; then
local outPath=$(send_repl "${attr_name}.outPath") || return 1
echo "editing: ${attr_name}:${position_file}"
sed -i "s|sha256 = \"$hash\"|hash = \"$hash\"|" $position_file
echo "${attr_name}:${position_file}:${outPath}" >> $EDITED_LOG
fi
fi
fi
}
verify_hash() {
local attr_name=$1
local position_file=$2
local outPath=$3
local new_outPath=$(send_repl "${attr_name}.outPath")
if [ $? -ne 0 ] || [[ "$outPath" != "$new_outPath" ]]; then
echo "problem: ${attr_name}:${position_file}"
# echo "'$outPath' != '$new_outPath'"
echo "${attr_name}:${position_file}:${outPath}" >> $PROBLEM_LOG
fi
}
[[ -f "$SEARCH_CACHE" ]] || nix search . ^ --json > $SEARCH_CACHE
pkg_list=($(cat $SEARCH_CACHE | jq --raw-output 'keys_unsorted | @sh'))
send_repl ":l ./."
sleep 1
echo "starting to replace"
for pkg_raw in ${pkg_list[@]}; do
pkg=${pkg_raw#*.*.}
pkg=${pkg%\'}
replace_hash $pkg
done
send_repl ":r"
sleep 1
echo "starting to examine"
while IFS= read -r line; do
IFS=':' read -r -a parts <<< "$line"
verify_hash ${parts[@]}
done < "$EDITED_LOG" It depends on |
Just noticed in the list, but |
I tried GitHub (only editing |
I've given up that list, because we cannot actually determine which fetcher it is (except for those that only serve specific sites). And since they are derivatives of fetchurl or fetchzip, it is not convenient to deprecate hash for a single fetcher |
Would that even work? pkgs.stdenv.mkDerivation {
name = "hash-algo-mismatch";
outputHash = "sha512-z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg==";
outputHashAlgo = "sha256";
} errors out in
|
I wrote some normalization helpers in #342072 which convert PS: To be clear, the prefered way for callers to specify the hash would still be the |
#342072 could probably use another reviewer, now that it's ~finalized, before it's merged and I go wrap almost-all fetchers with it. |
It looks like sha256 will eventually be deprecated in favor of hash: <NixOS#325892>.
It looks like sha256 will eventually be deprecated in favor of hash: <NixOS#325892>.
It looks like sha256 will eventually be deprecated in favor of hash: <NixOS#325892>.
It looks like sha256 will eventually be deprecated in favor of hash: <NixOS#325892>.
When we did not support SRI hash, we wrote a lot of
sha256 = "..."
, and some of new PRs are still written with this attribute. However, when using an empty string to obtain the correct hash from the error, the SRI hash is obtained, which causes some confusion.Let's move on from this old attribute. I don't expect to remove it within a certain period of time, but we can throw a warning to prevent this type of writing from continuing to appear in nixpkgs.
I did an experiment last time with cargoHash in #323983. I wrote the following script for this:
We can deprecate each fetcher's sha256 separately, instead of the entire hash, to avoid the burden of review:
I collapsed the check list because it's not feasible to deprecate one by one
fetchAttrs.hash
#342037hash
attribute #342031The text was updated successfully, but these errors were encountered: