'\" t .\" Title: nix-hash .\" Author: Eelco Dolstra .\" Generator: DocBook XSL Stylesheets v1.79.2 .\" Date: 12/12/2020 .\" Manual: Command Reference .\" Source: Nix 2.3.7 .\" Language: English .\" .TH "NIX\-HASH" "1" "12/12/2020" "Nix 2\&.3\&.7" "Command Reference" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" nix-hash \- compute the cryptographic hash of a path .SH "SYNOPSIS" .HP \w'\fBnix\-hash\fR\ 'u \fBnix\-hash\fR [\fB\-\-flat\fR] [\fB\-\-base32\fR] [\fB\-\-truncate\fR] [\fB\-\-type\fR\ \fIhashAlgo\fR] \fIpath\fR... .HP \w'\fBnix\-hash\fR\ 'u \fBnix\-hash\fR \fB\-\-to\-base16\fR \fIhash\fR... .HP \w'\fBnix\-hash\fR\ 'u \fBnix\-hash\fR \fB\-\-to\-base32\fR \fIhash\fR... .SH "DESCRIPTION" .PP The command \fBnix\-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 \fBnix\-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 \fBnix\-store\fR \fB\-\-dump\fR\&. Thus, nix\-hash \fIpath\fR yields the same cryptographic hash as nix\-store \-\-dump \fIpath\fR | md5sum\&. .SH "OPTIONS" .PP \fB\-\-flat\fR .RS 4 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 \fBmd5sum\fR and \fBsha1sum\fR\&. .RE .PP \fB\-\-base32\fR .RS 4 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 \fBfetchurl\fR)\&. .RE .PP \fB\-\-truncate\fR .RS 4 Truncate hashes longer than 160 bits (such as SHA\-256) to 160 bits\&. .RE .PP \fB\-\-type\fR \fIhashAlgo\fR .RS 4 Use the specified cryptographic hash algorithm, which can be one of md5, sha1, and sha256\&. .RE .PP \fB\-\-to\-base16\fR .RS 4 Don\(cqt hash anything, but convert the base\-32 hash representation \fIhash\fR to hexadecimal\&. .RE .PP \fB\-\-to\-base32\fR .RS 4 Don\(cqt hash anything, but convert the hexadecimal hash representation \fIhash\fR to base\-32\&. .RE .SH "EXAMPLES" .PP Computing the same hash as \fBnix\-prefetch\-url\fR: .sp .if n \{\ .RS 4 .\} .nf $ nix\-prefetch\-url file://<(echo test) 1lkgqb6fclns49861dwk9rzb6xnfkxbpws74mxnx01z9qyv1pjpj $ nix\-hash \-\-type sha256 \-\-flat \-\-base32 <(echo test) 1lkgqb6fclns49861dwk9rzb6xnfkxbpws74mxnx01z9qyv1pjpj .fi .if n \{\ .RE .\} .PP Computing hashes: .sp .if n \{\ .RS 4 .\} .nf $ mkdir test $ echo "hello" > 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 \-\-base32 test/ nvd61k9nalji1zl9rrdfmsmvyyjqpzg4 $ nix\-hash \-\-type sha256 \-\-flat test/ error: reading file `test/\*(Aq: Is a directory $ nix\-hash \-\-type sha256 \-\-flat test/world 5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03 .fi .if n \{\ .RE .\} .PP Converting between hexadecimal and base\-32: .sp .if n \{\ .RS 4 .\} .nf $ nix\-hash \-\-type sha1 \-\-to\-base32 e4fd8ba5f7bbeaea5ace89fe10255536cd60dab6 nvd61k9nalji1zl9rrdfmsmvyyjqpzg4 $ nix\-hash \-\-type sha1 \-\-to\-base16 nvd61k9nalji1zl9rrdfmsmvyyjqpzg4 e4fd8ba5f7bbeaea5ace89fe10255536cd60dab6 .fi .if n \{\ .RE .\} .sp .SH "AUTHOR" .PP \fBEelco Dolstra\fR .RS 4 Author .RE .SH "COPYRIGHT" .br Copyright \(co 2004-2018 Eelco Dolstra .br