Merge text hashing logic

#263
Opened by flokli at 2023-03-29T22·32+00

Nix has a concept of "text hashing", used in two different places right now:

tvix/nix-compat/src/derivation/mod.rs@calculate_derivation_path

Fields, separated by ::

The Sha256 digest of this is then passed to hash.CompressHash(digest, 20), to produce a store path.

tvix/nix-compat/src/derivation/utils.rs@path_with_references

Fields, separated by ::

The Sha256 digest of this is then passed to hash.CompressHash(digest, 20), to produce a store path.

This function is only used in the implementation of builtins.toFile.

/// Build a store path for a literal text file in the store that may
/// contain references.
pub fn path_with_references<S: AsRef<str>, I: IntoIterator<Item = S>, C: AsRef<[u8]>>(
    name: &str,
    content: C,
    references: I,
)

We should probably factor this code out into a common function.

  1. Done in cl/8364.

    flokli at 2023-03-30T11·35+00

  2. flokli closed this issue at 2023-03-30T14·15+00