.\" -*- mode: troff; coding: utf-8 -*- .TH "nix-hash" "1" "" .SH Name .LP \f(CRnix-hash\fR - compute the cryptographic hash of a path .SH Synopsis .LP \f(CRnix-hash\fR [\f(CR--flat\fR] [\f(CR--base32\fR] [\f(CR--truncate\fR] [\f(CR--type\fR \fIhashAlgo\fR] \fIpath…\fR .PP \f(CRnix-hash\fR [\f(CR--to-base16\fR|\f(CR--to-base32\fR|\f(CR--to-base64\fR|\f(CR--to-sri\fR] [\f(CR--type\fR \fIhashAlgo\fR] \fIhash…\fR .SH Description .LP The command \f(CRnix-hash\fR computes the cryptographic hash of the contents of each \fIpath\fR and prints it on standard output. By default, it computes an MD5 hash, but other hash algorithms are available as well. The hash is printed in hexadecimal. To generate the same hash as \f(CRnix-prefetch-url\fR you have to specify multiple arguments, see below for an example. .PP The hash is computed over a \fIserialisation\fR of each path: a dump of the file system tree rooted at the path. This allows directories and symlinks to be hashed as well as regular files. The dump is in the \fINAR format\fR produced by \fB\f(CRnix-store --dump\fR\fR. Thus, \f(CRnix-hash path\fR yields the same cryptographic hash as \f(CRnix-store --dump path | md5sum\fR. .SH Options .IP "\(bu" 3 \f(CR--flat\fR .br Print the cryptographic hash of the contents of each regular file \fIpath\fR. That is, do not compute the hash over the dump of \fIpath\fR. The result is identical to that produced by the GNU commands \f(CRmd5sum\fR and \f(CRsha1sum\fR. .IP "\(bu" 3 \f(CR--base16\fR .br Print the hash in a hexadecimal representation (default). .IP "\(bu" 3 \f(CR--base32\fR .br Print the hash in a base-32 representation rather than hexadecimal. This base-32 representation is more compact and can be used in Nix expressions (such as in calls to \f(CRfetchurl\fR). .IP "\(bu" 3 \f(CR--base64\fR .br Similar to \(enbase32, but print the hash in a base-64 representation, which is more compact than the base-32 one. .IP "\(bu" 3 \f(CR--sri\fR .br Print the hash in SRI format with base-64 encoding. The type of hash algorithm will be prepended to the hash string, followed by a hyphen (-) and the base-64 hash body. .IP "\(bu" 3 \f(CR--truncate\fR .br Truncate hashes longer than 160 bits (such as SHA-256) to 160 bits. .IP "\(bu" 3 \f(CR--type\fR \fIhashAlgo\fR .br Use the specified cryptographic hash algorithm, which can be one of \f(CRmd5\fR, \f(CRsha1\fR, \f(CRsha256\fR, and \f(CRsha512\fR. .IP "\(bu" 3 \f(CR--to-base16\fR .br Don’t hash anything, but convert the base-32 hash representation \fIhash\fR to hexadecimal. .IP "\(bu" 3 \f(CR--to-base32\fR .br Don’t hash anything, but convert the hexadecimal hash representation \fIhash\fR to base-32. .IP "\(bu" 3 \f(CR--to-base64\fR .br Don’t hash anything, but convert the hexadecimal hash representation \fIhash\fR to base-64. .IP "\(bu" 3 \f(CR--to-sri\fR .br Don’t hash anything, but convert the hexadecimal hash representation \fIhash\fR to SRI. .SH Examples .LP Computing the same hash as \f(CRnix-prefetch-url\fR: .LP .EX $ nix-prefetch-url file://<(echo test) 1lkgqb6fclns49861dwk9rzb6xnfkxbpws74mxnx01z9qyv1pjpj $ nix-hash --type sha256 --flat --base32 <(echo test) 1lkgqb6fclns49861dwk9rzb6xnfkxbpws74mxnx01z9qyv1pjpj .EE .PP Computing hashes: .LP .EX $ mkdir test $ echo \(dqhello\(dq > test/world $ nix-hash test/ (MD5 hash; default) 8179d3caeff1869b5ba1744e5a245c04 $ nix-store --dump test/ | md5sum (for comparison) 8179d3caeff1869b5ba1744e5a245c04 - $ nix-hash --type sha1 test/ e4fd8ba5f7bbeaea5ace89fe10255536cd60dab6 $ nix-hash --type sha1 --base16 test/ e4fd8ba5f7bbeaea5ace89fe10255536cd60dab6 $ nix-hash --type sha1 --base32 test/ nvd61k9nalji1zl9rrdfmsmvyyjqpzg4 $ nix-hash --type sha1 --base64 test/ 5P2Lpfe76upazon+ECVVNs1g2rY= $ nix-hash --type sha1 --sri test/ sha1-5P2Lpfe76upazon+ECVVNs1g2rY= $ nix-hash --type sha256 --flat test/ error: reading file \(gatest/': Is a directory $ nix-hash --type sha256 --flat test/world 5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03 .EE .PP Converting between hexadecimal, base-32, base-64, and SRI: .LP .EX $ nix-hash --type sha1 --to-base32 e4fd8ba5f7bbeaea5ace89fe10255536cd60dab6 nvd61k9nalji1zl9rrdfmsmvyyjqpzg4 $ nix-hash --type sha1 --to-base16 nvd61k9nalji1zl9rrdfmsmvyyjqpzg4 e4fd8ba5f7bbeaea5ace89fe10255536cd60dab6 $ nix-hash --type sha1 --to-base64 e4fd8ba5f7bbeaea5ace89fe10255536cd60dab6 5P2Lpfe76upazon+ECVVNs1g2rY= $ nix-hash --type sha1 --to-sri nvd61k9nalji1zl9rrdfmsmvyyjqpzg4 sha1-5P2Lpfe76upazon+ECVVNs1g2rY= $ nix-hash --to-base16 sha1-5P2Lpfe76upazon+ECVVNs1g2rY= e4fd8ba5f7bbeaea5ace89fe10255536cd60dab6 .EE