From c42f8ffa7fd917de518816e222bd359c4c226d2a Mon Sep 17 00:00:00 2001 From: Qyriad Date: Mon, 20 May 2024 20:54:00 -0600 Subject: [PATCH 1/4] build: make internal-api-docs PHONY Since we're skipping Meson's dependency tracking, for the internal-api-docs custom target, we should just consider it a phony target and build it on every request. Change-Id: I3b0bcea30ee9a4830023ccc5bededf995e96cccc --- doc/internal-api/meson.build | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/internal-api/meson.build b/doc/internal-api/meson.build index 35d8a0e5b..faa30f194 100644 --- a/doc/internal-api/meson.build +++ b/doc/internal-api/meson.build @@ -28,6 +28,7 @@ internal_api_docs = custom_target( output : 'html', install : true, install_dir : datadir / 'doc/nix/internal-api', + build_always_stale : true, ) alias_target('internal-api-html', internal_api_docs) From 12c0cc7b0eafde47838f4140c188df50627d3c32 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Mon, 20 May 2024 21:58:27 -0600 Subject: [PATCH 2/4] docs: linkify nix3-build mention in nix-build.md Change-Id: I462a8cf0da42b5045ce84b48dc1841ecdccbb89e --- doc/manual/src/command-ref/nix-build.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/manual/src/command-ref/nix-build.md b/doc/manual/src/command-ref/nix-build.md index b548edf82..92e642ddd 100644 --- a/doc/manual/src/command-ref/nix-build.md +++ b/doc/manual/src/command-ref/nix-build.md @@ -14,9 +14,8 @@ # Disambiguation -This man page describes the command `nix-build`, which is distinct from `nix -build`. For documentation on the latter, run `nix build --help` or see `man -nix3-build`. +This man page describes the command [`nix-build`](./new-cli/nix3-build.md), which is distinct from `nix build`. +For documentation on the latter, run `nix build --help` or see `man nix3-build`. # Description From 895767bcedf14968c117e4cb6e0689b680779461 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Tue, 21 May 2024 15:37:08 -0600 Subject: [PATCH 3/4] docs: document the file syntax things like nix-build take Change-Id: Ib6d68594a16132805ba5d97526e16f7b3633117e --- doc/manual/src/command-ref/fileish-summary.md | 12 +++++ doc/manual/src/command-ref/nix-build.md | 50 ++++++++++++++++--- doc/manual/src/command-ref/nix-instantiate.md | 9 ++-- 3 files changed, 61 insertions(+), 10 deletions(-) create mode 100644 doc/manual/src/command-ref/fileish-summary.md diff --git a/doc/manual/src/command-ref/fileish-summary.md b/doc/manual/src/command-ref/fileish-summary.md new file mode 100644 index 000000000..f4d7976df --- /dev/null +++ b/doc/manual/src/command-ref/fileish-summary.md @@ -0,0 +1,12 @@ + +- A normal filesystem path, like `/home/meow/nixfiles/default.nix` + - Including a directory, like `/home/meow/nixfiles`, equivalent to above +- A single lookup path, like `` or `` +- A URL to a tarball, like `https://github.com/NixOS/nixpkgs/archive/refs/heads/release-23.11.tar.gz` +- A flakeref, introduced by the prefix `flake:`, like `flake:git+https://git.lix.systems/lix-project/lix` +- A channel name, introduced by the prefix `channel:`, like `channel:nixpkgs-unstable`. + - This uses a hard-coded URL pattern and is *not* related to the subscribed channels managed by the [nix-channel](./nix-channel.md) command. diff --git a/doc/manual/src/command-ref/nix-build.md b/doc/manual/src/command-ref/nix-build.md index 92e642ddd..a91f9b7e0 100644 --- a/doc/manual/src/command-ref/nix-build.md +++ b/doc/manual/src/command-ref/nix-build.md @@ -4,7 +4,7 @@ # Synopsis -`nix-build` [*paths…*] +`nix-build` [*fileish…*] [`--arg` *name* *value*] [`--argstr` *name* *value*] [{`--attr` | `-A`} *attrPath*] @@ -20,19 +20,55 @@ For documentation on the latter, run `nix build --help` or see `man nix3-build`. # Description The `nix-build` command builds the derivations described by the Nix -expressions in *paths*. If the build succeeds, it places a symlink to +expressions in each *fileish*. If the build succeeds, it places a symlink to the result in the current directory. The symlink is called `result`. If there are multiple Nix expressions, or the Nix expressions evaluate to multiple derivations, multiple sequentially numbered symlinks are created (`result`, `result-2`, and so on). -If no *paths* are specified, then `nix-build` will use `default.nix` in +If no *fileish* is specified, then `nix-build` will use `default.nix` in the current directory, if it exists. -If an element of *paths* starts with `http://` or `https://`, it is -interpreted as the URL of a tarball that will be downloaded and unpacked -to a temporary location. The tarball must include a single top-level -directory containing at least a file named `default.nix`. +## Fileish Syntax + +A given *fileish* may take one of a few different forms, the first being a simple filesystem path, e.g. `nix-build /tmp/some-file.nix`. +This has the same semantics as the [import builtin](../language/builtins.md#builtins-import), so specifying a directory is equivalent to specifying `default.nix` within that directory. +It may also be a [search path](./env-common.html#env-NIX_PATH) (also known as a lookup path) like ``, which is convenient to use with `--attr`/`-A`: + +```console +$ nix-build '' -A firefox +``` + +(Note the quotation marks around ``, which will be necessary in most Unix shells.) + +If a *fileish* starts with `http://` or `https://`, it is interpreted as the URL of a tarball which will be fetched and unpacked. +Lix will then `import` the unpacked directory, so these tarballs must include at least single top-level directory with a file called `default.nix` +For example, you could build from a specific version of Nixpkgs with something like: + +```console +$ nix-build "https://github.com/NixOS/nixpkgs/archive/refs/heads/release-23.11.tar.gz" -A firefox +``` + +If a path starts with `flake:`, the rest of the argument is interpreted as a [flakeref](./new-cli/nix3-flake.html#flake-references) (see `nix flake --help` or `man nix3-flake`), which requires the "flakes" experimental feature to be enabled. +Lix will fetch the flake, and then `import` its unpacked directory, so the flake must include a file called `default.nix`. +For example, the flake analogues to the above `nix-build` commands are: + +```console +$ nix-build flake:nixpkgs -A firefox +$ nix-build flake:github:NixOS/nixpkgs/release-23.11 -A firefox +``` + +Finally, for legacy reasons, if a path starts with `channel:`, the rest of the argument is interpreted as the name of a channel to fetch from `https://nixos.org/channels/$CHANNEL_NAME/nixexprs.tar.xz`. +This is a **hard coded URL** pattern and is *not* related the subscribed channels managed by the [nix-channel](./nix-channel.md) command. + +> **Note**: any of the special syntaxes may always be disambiguated by prefixing the path. +> For example: a file in the current directory literally called `` can be addressed as `./`, to escape the special interpretation. + +In summary, a path argument may be one of: + +{{#include ./fileish-summary.md}} + +## Notes `nix-build` is essentially a wrapper around [`nix-instantiate`](nix-instantiate.md) (to translate a high-level Nix diff --git a/doc/manual/src/command-ref/nix-instantiate.md b/doc/manual/src/command-ref/nix-instantiate.md index 479c9abcf..f9c7fcac5 100644 --- a/doc/manual/src/command-ref/nix-instantiate.md +++ b/doc/manual/src/command-ref/nix-instantiate.md @@ -11,7 +11,7 @@ [{`--attr`| `-A`} *attrPath*] [`--add-root` *path*] [`--expr` | `-E`] - *files…* + *fileish…* `nix-instantiate` `--find-file` *files…* @@ -25,8 +25,11 @@ of the resulting store derivations are printed on standard output. [store derivation]: ../glossary.md#gloss-store-derivation -If *files* is the character `-`, then a Nix expression will be read from -standard input. +If *fileish* is the character `-`, then a Nix expression will be read from standard input. +Otherwise, each *fileish* is interpreted the same as with [nix-build](./nix-build.md#Path_Syntax). +See that section for complete details (`nix-build --help`), but in summary, a path argument may be one of: + +{{#include ./fileish-summary.md}} # Options From f567e571c13551d5465867e2f23713aeb4cccbab Mon Sep 17 00:00:00 2001 From: Qyriad Date: Wed, 22 May 2024 17:15:45 -0600 Subject: [PATCH 4/4] docstrings: NixRepl::getDerivationPath: exceptions directly thrown getDerivationPath() directly throws nix::Error for invalid derivations Change-Id: I81ead950060b789794fa683b61c6349fece1690d --- src/libcmd/repl.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index 525c25560..db9d0bd27 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -106,6 +106,11 @@ struct NixRepl void initEnv() override; virtual StringSet completePrefix(const std::string & prefix) override; + + /** + * @exception nix::Error thrown directly if the expression does not evaluate + * to a derivation, or evaluates to an invalid derivation. + */ StorePath getDerivationPath(Value & v); ProcessLineResult processLine(std::string line);