aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorYueh-Shun Li <44064051+ShamrockLee@users.noreply.github.com>2023-03-16 00:33:58 +0800
committerYueh-Shun Li <44064051+ShamrockLee@users.noreply.github.com>2023-03-16 03:08:42 +0800
commitc27d358abba7154f16795d48d2a44fa856ab6b1e (patch)
treec66d05dc9a430c8fe7026493f2f2c57401c255c6 /doc
parent08510c5ed0fe4b9f8266bb37c859f0ed7fa342db (diff)
nix-hash: support base-64 and SRI format
Add the --base64 and --sri flags for the Base64 and SRI format output. Add the --base16 flag to explicitly specify the hexadecimal format. Add the --to-base64 and --to-sri flag to convert a hash to the above mentioned format.
Diffstat (limited to 'doc')
-rw-r--r--doc/manual/src/command-ref/nix-hash.md44
-rw-r--r--doc/manual/src/release-notes/rl-next.md7
2 files changed, 47 insertions, 4 deletions
diff --git a/doc/manual/src/command-ref/nix-hash.md b/doc/manual/src/command-ref/nix-hash.md
index 45f67f1c5..90fedfb14 100644
--- a/doc/manual/src/command-ref/nix-hash.md
+++ b/doc/manual/src/command-ref/nix-hash.md
@@ -6,9 +6,7 @@
`nix-hash` [`--flat`] [`--base32`] [`--truncate`] [`--type` *hashAlgo*] *path…*
-`nix-hash` `--to-base16` *hash…*
-
-`nix-hash` `--to-base32` *hash…*
+`nix-hash` [`--to-base16`|`--to-base32`|`--to-base64`|`--to-sri`] [`--type` *hashAlgo*] *hash…*
# Description
@@ -35,11 +33,23 @@ md5sum`.
The result is identical to that produced by the GNU commands
`md5sum` and `sha1sum`.
+ - `--base16`\
+ Print the hash in a hexadecimal representation (default).
+
- `--base32`\
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 `fetchurl`).
+ - `--base64`\
+ Similar to --base32, but print the hash in a base-64 representation,
+ which is more compact than the base-32 one.
+
+ - `--sri`\
+ 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.
+
- `--truncate`\
Truncate hashes longer than 160 bits (such as SHA-256) to 160 bits.
@@ -55,6 +65,14 @@ md5sum`.
Don’t hash anything, but convert the hexadecimal hash representation
*hash* to base-32.
+ - `--to-base64`\
+ Don’t hash anything, but convert the hexadecimal hash representation
+ *hash* to base-64.
+
+ - `--to-sri`\
+ Don’t hash anything, but convert the hexadecimal hash representation
+ *hash* to SRI.
+
# Examples
Computing the same hash as `nix-prefetch-url`:
@@ -81,9 +99,18 @@ $ nix-store --dump test/ | md5sum (for comparison)
$ 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 `test/': Is a directory
@@ -91,7 +118,7 @@ $ nix-hash --type sha256 --flat test/world
5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03
```
-Converting between hexadecimal and base-32:
+Converting between hexadecimal, base-32, base-64, and SRI:
```console
$ nix-hash --type sha1 --to-base32 e4fd8ba5f7bbeaea5ace89fe10255536cd60dab6
@@ -99,4 +126,13 @@ 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
```
diff --git a/doc/manual/src/release-notes/rl-next.md b/doc/manual/src/release-notes/rl-next.md
index c78b20eed..b8d14e605 100644
--- a/doc/manual/src/release-notes/rl-next.md
+++ b/doc/manual/src/release-notes/rl-next.md
@@ -4,6 +4,13 @@
passed the `--stdin` flag. This is primarily useful when you have a large amount of paths which
exceed the OS arg limit.
+* The `nix-hash` command now supports Base64 and SRI. Use the flags `--base64`
+ or `--sri` to specify the format of output hash as Base64 or SRI, and `--to-base64`
+ or `--to-sri` to convert a hash to Base64 or SRI format, respectively.
+
+ As the choice of hash formats is no longer binary, the `--base16` flag is also added
+ to explicitly specify the Base16 format, which is still the default.
+
* The special handling of an [installable](../command-ref/new-cli/nix.md#installables) with `.drv` suffix being interpreted as all of the given [store derivation](../glossary.md#gloss-store-derivation)'s output paths is removed, and instead taken as the literal store path that it represents.
The new `^` syntax for store paths introduced in Nix 2.13 allows explicitly referencing output paths of a derivation.