stdenv: introduce baseHash() to replace stripHash()

stripHash uses a global variable to communicate it's computation
results, but it's not necessary. You can just pipe to stdout in a
subshell. A function mostly behaves like just another command.

baseHash() also introduces a suffix-stripping capability since it's
something the users of the function tend to use.
This commit is contained in:
zimbatm
2016-06-25 14:20:56 +01:00
parent 7060eaf0bb
commit e71a5cb878
12 changed files with 45 additions and 36 deletions
+24 -20
View File
@@ -1191,31 +1191,35 @@ echo @foo@
<replaceable>file</replaceable>.</para></listitem>
</varlistentry>
<varlistentry xml:id='fun-baseHash'>
<term>
<function>baseHash</function>
<replaceable>path</replaceable>
<replaceable>suffix</replaceable>
</term>
<listitem><para>Strips the directory and hash part of a store
path, storing the name part in the environment variable
<literal>strippedName</literal>. If <literal>suffix</literal> is also
provided, the suffix will also be removed. For example:</para>
<programlisting>
baseHash "/nix/store/9s9r019176g7cvn2nvcw41gsp862y6b4-coreutils-8.24"
# prints coreutils-8.24
</programlisting>
<programlisting>
baseHash "/nix/store/0016702zbydafsr20n9l1dcw7x2bf6jj-arraysugar-0.1.0.gem" .gem
# prints arraysugar-0.1.0
</programlisting>
</listitem>
</varlistentry>
<varlistentry xml:id='fun-stripHash'>
<term><function>stripHash</function>
<replaceable>path</replaceable></term>
<listitem><para>Strips the directory and hash part of a store
path, storing the name part in the environment variable
<literal>strippedName</literal>. For example:
<programlisting>
stripHash "/nix/store/9s9r019176g7cvn2nvcw41gsp862y6b4-coreutils-8.24"
# prints coreutils-8.24
echo $strippedName
</programlisting>
If you wish to store the result in another variable, then the
following idiom may be useful:
<programlisting>
name="/nix/store/9s9r019176g7cvn2nvcw41gsp862y6b4-coreutils-8.24"
someVar=$(stripHash $name; echo $strippedName)
</programlisting>
</para></listitem>
<listitem><para>Deprecated. Use baseHash instead.</para></listitem>
</varlistentry>
</variablelist>