Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Nix Hash – Hashes in Nix (Base16 vs. Base32 vs. Base64 for Encoding SHA256/512) (nixos.wiki)
5 points by peter_d_sherman on March 26, 2024 | hide | past | favorite | 1 comment


>"A hash – which is simply a sequence of bytes – is usually encoded in order to be representable as string. Common encodings are base16 (commonly called "hex"), base32 and base64. Note that the base32 is a custom one that is not documented nor standardized in any way! If possible, use the provided hashing tools to convert hashes to it (see below).

base32 is used by Nix in a lot of places because it is shorter than hex but can still safely be part of a file path (as it contains no slashes)."

(For future OS system engineers: Base64 can apparently NOT be used for any system where the Base64 encoding is used for part of a file or directory name -- because it contains slashes! (Periods and asterisks and other special filesystem characters are probably bad things to use in filenames as well -- but that discussion is probably a bit outside the scope of this post!))

Related:

Nix Error: "error: invalid base-32 hash" (When specifying a 'sha256 =' value -- with a valid SHA256 -- but the SHA256 is not in valid base32 which is what Nix apparently expects! Tricky!)

"sha256 - Nothing makes sense":

https://github.com/NixOS/nix/issues/806




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: