Allow relative paths in --store option#3736
Conversation
In nix commands which accept --store options, we can now specify a relative path, which will be canonicalized.
|
It works, but it's marked as WIP as some tests should be added for this. |
src/libstore/store-api.cc
Outdated
| if (uri == "daemon") { | ||
| return tDaemon; | ||
| } else if (uri == "local" || hasPrefix(uri, "/")) { | ||
| } else if (uri == "local" || hasPrefix(uri, "/") || hasPrefix(uri, "./")) { |
There was a problem hiding this comment.
Might make sense to also allow . as a path
There was a problem hiding this comment.
The cost of that would be divergence from the nix expression language though, right?
There was a problem hiding this comment.
this already happens with cli args. for instance:
nix build -f . hello
There was a problem hiding this comment.
but does -f <url> work? Because we are overloading URL and relative path syntax, and URL syntax already is infamous for having parser mistakes/ambiguities/vulnerabilities, I rather move slowly. We can always add . later.
Of course, if @edolstra wants / there's concensus to go ahead and do ., we'll happily add it, but I rather advocate for the smallest change that gets the job done.
There was a problem hiding this comment.
url's do work (although they have to be in tar format):
nix build -f https://github.com/NixOS/nixpkgs/archive/master.tar.gz hello
There was a problem hiding this comment.
rules for it are:
nix/src/libexpr/common-eval-args.cc
Lines 74 to 85 in 3f01fa1
There was a problem hiding this comment.
OK fair, but it as wrong of me to compare -f <url> in the first place, because this sort of "each store parses the thing" means having else cases is no good either---everything should be if (...) { ... } else return nullptr.
Now we could still do ., yes. My above does not work argument against that, I will totally grant.
There was a problem hiding this comment.
@edolstra's weak preference is if it doesn't contain :// and does contain / then it is deemed a path and is turned into a LocalStore.
There was a problem hiding this comment.
In meeting we got @edolstra's preference, and I just updated the PR accordingly.
8e5be0c to
4178f36
Compare
The was Eelco's prefered logic, and it looks good to me!
| throw Error("don't know how to open Nix store '%s'", uri); | ||
| } | ||
|
|
||
| static bool isNonUriPath(const std::string & spec) { |
There was a problem hiding this comment.
Can you just use !isUri from file-transfer?
…te-regStore Remove storetype delegate reg store -- contains #3736
In nix commands which accept --store options, we can now specify a
relative path, which will be canonicalized. The relative path must start
with
./like in thenixlanguage.Fixes #3734