Repository navigation
Open
Open
Copy link
Labels
5.scope: trackingLong-lived issue tracking long-term fixes or multiple sub-problems6.topic: architectureRelating to code and API architecture of Nixpkgs
Description
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:
#!/usr/bin/env bash
process_line() {
local filename=${1%:}
if [[ $4 =~ \"(.*)\"\; ]]; then
local sha256="${BASH_REMATCH[1]}"
fi
[[ -z $sha256 ]] && return 0
local hash=$(nix hash to-sri --type sha256 $sha256)
echo "Processing: $filename"
echo " $sha256 => $hash"
sed -i "s|sha256 = \"$sha256\"|hash = \"$hash\"|" $filename
}
# split output by line
grep -r 'sha256 = ' . | while IFS= read -r line; do
# split them further by space
read -r -a parts <<< "$line"
process_line "${parts[@]}"
doneWe 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
- buildBazelPackage buildBazelPackage: support
fetchAttrs.hash#342037 - fetch-scm
- fetchCrate
- fetchDebianPatch
- fetchDockerConfig
- fetchDockerLayer
- fetchFirefoxAddon
- fetchFrom9Front
- fetchFromBitbucket fetchFromBitBucket: deprecate sha256 attribute #326028
- fetchFromGitHub
- fetchFromGitLab
- fetchFromGitea
- fetchFromGithub
- fetchFromGitiles
- fetchFromRepoOrCz
- fetchFromSavannah
- fetchFromSourcehut
- fetchHex
- fetchMavenArtifact
- fetchNextcloudApp
- fetchNpmDeps
- fetchNuGet
- fetchPypi
- fetchPypiLegacy
- fetchRepoProject fetchRepoProject: support
hashattribute #342031 - fetchTarball
- fetchYarnDeps
- fetchbower
- fetchbzr
- fetchcvs
- fetchdarcs
- fetchdocker
- fetchegg
- fetchfossil
- fetchgit
- fetchgitLocal
- fetchgx
- fetchhg
- fetchipfs
- fetchit
- fetchmail
- fetchmail_7
- fetchmtn
- fetchpatch
- fetchpatch2
- fetchpijul
- fetchs3
- fetchsvn
- fetchsvnrevision
- fetchsvnssh
- fetchtorrent (Looks like there is no support for sha256 attribute?)
- fetchurl
- fetchutils
- fetchzip
Reacted by Jonas Heinrich, Yohann Boniface, Gergő Gutyina, goyalyashpal, Victor Engmark, isabel and Cosima Neidahl
Reacted by goyalyashpal
Metadata
Metadata
Assignees
Labels
5.scope: trackingLong-lived issue tracking long-term fixes or multiple sub-problems6.topic: architectureRelating to code and API architecture of Nixpkgs
Activity
eclairevoyant commentedon Jul 9, 2024
You can still use the SRI sha256 hash in the
sha256attr.(Not disagreeing with the deprecation though.)
emilazy commentedon Jul 9, 2024
(Taking the opportunity to plug the related
lib.fakeHash, which maybe only I use, because it lets you avoid remembering how manyAs you need.)Aleksanaa commentedon Jul 9, 2024
Yes, it's like
sha256 = "sha256-...", if after some day we decide to use sha512 by default, it will becomesha256 = "sha512-"eclairevoyant commentedon Jul 9, 2024
@emilazyI usually just use""honestly, as Aleksanaa mentioned.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
cargoHashas you did in #323983, because we know it will only affect the rust builder/fetcher. But sometimes people use custom builders and scripts (especially update scripts) that may break with this. I will try to come up with a more robust script that only touches one fetcher at a time.Aleksanaa commentedon Jul 9, 2024
Yes, otherwise ofBorg will fail?
I'm adding one more grep like
grep -rl "fetchFromBitbucket" . | xargs grep -r 'sha256 = ' | while IFS= read -r line; doand it turned out well. But update script is indeed a problem and it is not within the scope of our scan.emilazy commentedon Jul 9, 2024
(Thank you, I had no idea
""works! I could swear it didn’t in the past. Sorry for the tangent.)eclairevoyant commentedon Jul 9, 2024
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.
pyrox0 commentedon Jul 12, 2024
There are many fetchers that are based on others(
fetchFromOrCzis based onfetchzip,fetchFrom9Frontis based on eitherfetchurlorfetchgit, etc). Will the sha256 attribute have to be deprecated in those fetchers first, or in the underlying ones?Aleksanaa commentedon Jul 13, 2024
So I wrote this script:
my script
It depends on
jqandansi2txt. Currently, because it is single-threaded logic, a treewide operation takes about 10 minutes. Feel free to modify it according to your ideas.pyrox0 commentedon Jul 13, 2024
Just noticed in the list, but
fetchitis not a fetcher, it's a podman tool. Should probably be removed.Aleksanaa commentedon Jul 13, 2024
I tried GitHub (only editing
sha256 = "sha256-), and there are 3000+ direct editions, including 1000+ objections (we can modify the check to revert changes directly, using sed or git, depending on the speed). We can still edit 2000+ files painlessly after all. Might be related to #301014Aleksanaa commentedon Jul 13, 2024
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
nicoonoclaste commentedon Sep 15, 2024
Would that even work?
errors out in
builtins.derivationStrictwith12 remaining items
treefmt: sha256 -> hash for fetchFromSourcehut
treefmt: sha256 -> hash for fetchFromBitbucket
treefmt: sha256 -> hash for fetchFromBitbucket
treefmt: sha256 -> hash for fetchFromGitea
treefmt: sha256 -> hash for fetchFromBitbucket
treefmt: sha256 -> hash for fetchFromCodeberg
treefmt: sha256 -> hash for fetchFromBitbucket
treefmt: sha256 -> hash for fetchFromBitbucket
treefmt: sha256 -> hash for fetchFromBitbucket
treefmt: sha256 -> hash for fetchFromForgejo
treefmt: sha256 -> hash for fetchFromBitbucket
treefmt: sha256 -> hash for fetchFromBitbucket
treefmt: sha256 -> hash for fetchFromGitHub