about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-10-07T12·55+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-10-07T12·55+0200
commitf08449ccbd2009b858aae18341aedf3d0829b91a (patch)
tree0a5a9a6fe1a009dd9243db14a0e8f1d302cbf887
parente4abf8610be3d9f3023a538460f87be8f31bca2d (diff)
nix-prefetch-url: Add --name option
This allows overriding the name component of the resulting Nix store
path, which is necessary if the base name of the URI contains
"illegal" characters.
-rw-r--r--doc/manual/command-ref/nix-prefetch-url.xml12
-rw-r--r--src/nix-prefetch-url/nix-prefetch-url.cc10
2 files changed, 19 insertions, 3 deletions
diff --git a/doc/manual/command-ref/nix-prefetch-url.xml b/doc/manual/command-ref/nix-prefetch-url.xml
index e1f0c8e5447c..016d8863a94c 100644
--- a/doc/manual/command-ref/nix-prefetch-url.xml
+++ b/doc/manual/command-ref/nix-prefetch-url.xml
@@ -91,6 +91,18 @@ downloaded file in the Nix store is also printed.</para>
 
   </varlistentry>
 
+  <varlistentry><term><option>--name</option></term>
+
+    <listitem><para>Override the name of the file in the Nix store. By
+    default, this is
+    <literal><replaceable>hash</replaceable>-<replaceable>basename</replaceable></literal>,
+    where <replaceable>basename</replaceable> is the last component of
+    <replaceable>url</replaceable>. Overriding the name is necessary
+    when <replaceable>basename</replaceable> contains characters that
+    are not allowed in Nix store paths.</para></listitem>
+
+  </varlistentry>
+
 </variablelist>
 
 </refsection>
diff --git a/src/nix-prefetch-url/nix-prefetch-url.cc b/src/nix-prefetch-url/nix-prefetch-url.cc
index a3932d6bed55..0a8166da4aa1 100644
--- a/src/nix-prefetch-url/nix-prefetch-url.cc
+++ b/src/nix-prefetch-url/nix-prefetch-url.cc
@@ -75,6 +75,8 @@ int main(int argc, char * * argv)
             }
             else if (*arg == "--unpack")
                 unpack = true;
+            else if (*arg == "--name")
+                name = getArg(*arg, arg, end);
             else if (parseAutoArgs(arg, end, autoArgs_))
                 ;
             else if (parseSearchPathArg(arg, end, searchPath))
@@ -125,9 +127,11 @@ int main(int argc, char * * argv)
                 unpack = state.forceString(*attr->value) == "recursive";
 
             /* Extract the name. */
-            attr = v.attrs->find(state.symbols.create("name"));
-            if (attr != v.attrs->end())
-                name = state.forceString(*attr->value);
+            if (name.empty()) {
+                attr = v.attrs->find(state.symbols.create("name"));
+                if (attr != v.attrs->end())
+                    name = state.forceString(*attr->value);
+            }
         }
 
         /* Figure out a name in the Nix store. */