package nixhash import ( "crypto/sha256" "encoding/hex" "sort" "strings" "github.com/numtide/go-nix/nixbase32" ) func StorePathForText(name, s, storePath string, references []string) string { strHash := sha256.Sum256([]byte(s)) sort.Strings(references) var typeStrBuilder strings.Builder typeStrBuilder.WriteString("text") for _, ref := range references { typeStrBuilder.WriteString(":") typeStrBuilder.WriteString(ref) } typeStr := typeStrBuilder.String() sStr := typeStr + ":sha256:" + hex.EncodeToString(strHash[:]) + ":" + storePath + ":" + name sHash := sha256.Sum256([]byte(sStr)) sCompressedHash := make([]byte, 20) for i := range sHash { sCompressedHash[i%len(sCompressedHash)] ^= sHash[i] } return nixbase32.EncodeToString(sCompressedHash[:]) }