diff --git a/doc/manual/command-ref/nix-prefetch-url.xml b/doc/manual/command-ref/nix-prefetch-url.xml index e1f0c8e54..016d8863a 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. + + + Override the name of the file in the Nix store. By + default, this is + hash-basename, + where basename is the last component of + url. Overriding the name is necessary + when basename contains characters that + are not allowed in Nix store paths. + + + diff --git a/src/nix-prefetch-url/nix-prefetch-url.cc b/src/nix-prefetch-url/nix-prefetch-url.cc index a3932d6be..0a8166da4 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. */