mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 00:08:07 +02:00
Merge pull request #10563 from hercules-ci/doc-glossary-base-directory
doc/glossary: Add base directory
This commit is contained in:
commit
c6526fa33b
5 changed files with 41 additions and 4 deletions
|
@ -295,6 +295,25 @@
|
||||||
[path]: ./language/values.md#type-path
|
[path]: ./language/values.md#type-path
|
||||||
[attribute name]: ./language/values.md#attribute-set
|
[attribute name]: ./language/values.md#attribute-set
|
||||||
|
|
||||||
|
- [base directory]{#gloss-base-directory}
|
||||||
|
|
||||||
|
The location from which relative paths are resolved.
|
||||||
|
|
||||||
|
- For expressions in a file, the base directory is the directory containing that file.
|
||||||
|
This is analogous to the directory of a [base URL](https://datatracker.ietf.org/doc/html/rfc1808#section-3.3).
|
||||||
|
<!-- which is sufficient for resolving non-empty URLs -->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
The wording here may look awkward, but it's for these reasons:
|
||||||
|
* "with --expr": it's a flag, and not an option with an accompanying value
|
||||||
|
* "written in": the expression itself must be written as an argument,
|
||||||
|
whereas the more natural "passed as an argument" allows an interpretation
|
||||||
|
where the expression could be passed by file name.
|
||||||
|
-->
|
||||||
|
- For expressions written in command line arguments with [`--expr`](@docroot@/command-ref/opt-common.html#opt-expr), the base directory is the current working directory.
|
||||||
|
|
||||||
|
[base directory]: #gloss-base-directory
|
||||||
|
|
||||||
- [experimental feature]{#gloss-experimental-feature}
|
- [experimental feature]{#gloss-experimental-feature}
|
||||||
|
|
||||||
Not yet stabilized functionality guarded by named experimental feature flags.
|
Not yet stabilized functionality guarded by named experimental feature flags.
|
||||||
|
|
|
@ -97,8 +97,8 @@
|
||||||
is not a path: it's parsed as an expression that selects the
|
is not a path: it's parsed as an expression that selects the
|
||||||
attribute `sh` from the variable `builder`. If the file name is
|
attribute `sh` from the variable `builder`. If the file name is
|
||||||
relative, i.e., if it does not begin with a slash, it is made
|
relative, i.e., if it does not begin with a slash, it is made
|
||||||
absolute at parse time relative to the directory of the Nix
|
absolute at parse time relative to the [base directory](@docroot@/glossary.md#gloss-base-directory).
|
||||||
expression that contained it. For instance, if a Nix expression in
|
For instance, if a Nix expression in
|
||||||
`/foo/bar/bla.nix` refers to `../xyzzy/fnord.nix`, the absolute path
|
`/foo/bar/bla.nix` refers to `../xyzzy/fnord.nix`, the absolute path
|
||||||
is `/foo/xyzzy/fnord.nix`.
|
is `/foo/xyzzy/fnord.nix`.
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@
|
||||||
e.g. `~/foo` would be equivalent to `/home/edolstra/foo` for a user
|
e.g. `~/foo` would be equivalent to `/home/edolstra/foo` for a user
|
||||||
whose home directory is `/home/edolstra`.
|
whose home directory is `/home/edolstra`.
|
||||||
|
|
||||||
For instance, evaluating `"${./foo.txt}"` will cause `foo.txt` in the current directory to be copied into the Nix store and result in the string `"/nix/store/<hash>-foo.txt"`.
|
For instance, evaluating `"${./foo.txt}"` will cause `foo.txt` in the base directory to be copied into the Nix store and result in the string `"/nix/store/<hash>-foo.txt"`.
|
||||||
|
|
||||||
Note that the Nix language assumes that all input files will remain _unchanged_ while evaluating a Nix expression.
|
Note that the Nix language assumes that all input files will remain _unchanged_ while evaluating a Nix expression.
|
||||||
For example, assume you used a file path in an interpolated string during a `nix repl` session.
|
For example, assume you used a file path in an interpolated string during a `nix repl` session.
|
||||||
|
|
|
@ -38,6 +38,9 @@ private:
|
||||||
std::map<std::string, AutoArg> autoArgs;
|
std::map<std::string, AutoArg> autoArgs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param baseDir Optional [base directory](https://nixos.org/manual/nix/unstable/glossary#gloss-base-directory)
|
||||||
|
*/
|
||||||
SourcePath lookupFileArg(EvalState & state, std::string_view s, const Path * baseDir = nullptr);
|
SourcePath lookupFileArg(EvalState & state, std::string_view s, const Path * baseDir = nullptr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,24 +68,39 @@ struct FlakeRef
|
||||||
|
|
||||||
std::ostream & operator << (std::ostream & str, const FlakeRef & flakeRef);
|
std::ostream & operator << (std::ostream & str, const FlakeRef & flakeRef);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param baseDir Optional [base directory](https://nixos.org/manual/nix/unstable/glossary#gloss-base-directory)
|
||||||
|
*/
|
||||||
FlakeRef parseFlakeRef(
|
FlakeRef parseFlakeRef(
|
||||||
const std::string & url,
|
const std::string & url,
|
||||||
const std::optional<Path> & baseDir = {},
|
const std::optional<Path> & baseDir = {},
|
||||||
bool allowMissing = false,
|
bool allowMissing = false,
|
||||||
bool isFlake = true);
|
bool isFlake = true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param baseDir Optional [base directory](https://nixos.org/manual/nix/unstable/glossary#gloss-base-directory)
|
||||||
|
*/
|
||||||
std::optional<FlakeRef> maybeParseFlake(
|
std::optional<FlakeRef> maybeParseFlake(
|
||||||
const std::string & url, const std::optional<Path> & baseDir = {});
|
const std::string & url, const std::optional<Path> & baseDir = {});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param baseDir Optional [base directory](https://nixos.org/manual/nix/unstable/glossary#gloss-base-directory)
|
||||||
|
*/
|
||||||
std::pair<FlakeRef, std::string> parseFlakeRefWithFragment(
|
std::pair<FlakeRef, std::string> parseFlakeRefWithFragment(
|
||||||
const std::string & url,
|
const std::string & url,
|
||||||
const std::optional<Path> & baseDir = {},
|
const std::optional<Path> & baseDir = {},
|
||||||
bool allowMissing = false,
|
bool allowMissing = false,
|
||||||
bool isFlake = true);
|
bool isFlake = true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param baseDir Optional [base directory](https://nixos.org/manual/nix/unstable/glossary#gloss-base-directory)
|
||||||
|
*/
|
||||||
std::optional<std::pair<FlakeRef, std::string>> maybeParseFlakeRefWithFragment(
|
std::optional<std::pair<FlakeRef, std::string>> maybeParseFlakeRefWithFragment(
|
||||||
const std::string & url, const std::optional<Path> & baseDir = {});
|
const std::string & url, const std::optional<Path> & baseDir = {});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param baseDir Optional [base directory](https://nixos.org/manual/nix/unstable/glossary#gloss-base-directory)
|
||||||
|
*/
|
||||||
std::tuple<FlakeRef, std::string, ExtendedOutputsSpec> parseFlakeRefWithFragmentAndExtendedOutputsSpec(
|
std::tuple<FlakeRef, std::string, ExtendedOutputsSpec> parseFlakeRefWithFragmentAndExtendedOutputsSpec(
|
||||||
const std::string & url,
|
const std::string & url,
|
||||||
const std::optional<Path> & baseDir = {},
|
const std::optional<Path> & baseDir = {},
|
||||||
|
|
|
@ -41,7 +41,7 @@ public:
|
||||||
virtual std::string doc() { return ""; }
|
virtual std::string doc() { return ""; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the base directory for the command.
|
* @brief Get the [base directory](https://nixos.org/manual/nix/unstable/glossary#gloss-base-directory) for the command.
|
||||||
*
|
*
|
||||||
* @return Generally the working directory, but in case of a shebang
|
* @return Generally the working directory, but in case of a shebang
|
||||||
* interpreter, returns the directory of the script.
|
* interpreter, returns the directory of the script.
|
||||||
|
|
Loading…
Reference in a new issue