about summary refs log tree commit diff
path: root/src/nix-prefetch-url
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-10-07T12·47+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-10-07T12·47+0200
commite4abf8610be3d9f3023a538460f87be8f31bca2d (patch)
treedf401c8dc41f71d61eb730816e3a9c16370ae5b4 /src/nix-prefetch-url
parentb54f447df9def487317bfcf78628ebf207879c3a (diff)
nix-prefetch-url -A: Use "name" attribute from Nix expression
This is in particular useful for fetchFromGitHub et al., ensuring that
the store path produced by nix-prefetch-url corresponds to what those
functions expect.
Diffstat (limited to 'src/nix-prefetch-url')
-rw-r--r--src/nix-prefetch-url/nix-prefetch-url.cc9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/nix-prefetch-url/nix-prefetch-url.cc b/src/nix-prefetch-url/nix-prefetch-url.cc
index 5da8d968b9f9..a3932d6bed55 100644
--- a/src/nix-prefetch-url/nix-prefetch-url.cc
+++ b/src/nix-prefetch-url/nix-prefetch-url.cc
@@ -54,6 +54,7 @@ int main(int argc, char * * argv)
         string attrPath;
         std::map<string, string> autoArgs_;
         bool unpack = false;
+        string name;
 
         parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) {
             if (*arg == "--help")
@@ -122,10 +123,16 @@ int main(int argc, char * * argv)
                 printMsg(lvlInfo, "warning: this does not look like a fetchurl call");
             else
                 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);
         }
 
         /* Figure out a name in the Nix store. */
-        auto name = baseNameOf(uri);
+        if (name.empty())
+            name = baseNameOf(uri);
         if (name.empty())
             throw Error(format("cannot figure out file name for ‘%1%’") % uri);