Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into lazy-trees-post-s…
Browse files Browse the repository at this point in the history
…ettings
  • Loading branch information
Ericson2314 committed Jul 21, 2024
2 parents 750ba9f + 56757e1 commit 3426e54
Show file tree
Hide file tree
Showing 226 changed files with 4,182 additions and 1,562 deletions.
53 changes: 53 additions & 0 deletions doc/manual/rl-next/repl-doc-renders-doc-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
synopsis: "`nix-repl`'s `:doc` shows documentation comments"
significance: significant
issues:
- 3904
- 10771
prs:
- 1652
- 9054
- 11072
---

`nix repl` has a `:doc` command that previously only rendered documentation for internally defined functions.
This feature has been extended to also render function documentation comments, in accordance with [RFC 145].

Example:

```
nix-repl> :doc lib.toFunction
Function toFunction
… defined at /home/user/h/nixpkgs/lib/trivial.nix:1072:5
Turns any non-callable values into constant functions. Returns
callable values as is.
Inputs
v
: Any value
Examples
:::{.example}
## lib.trivial.toFunction usage example
| nix-repl> lib.toFunction 1 2
| 1
|
| nix-repl> lib.toFunction (x: x + 1) 2
| 3
:::
```

Known limitations:
- It does not render documentation for "formals", such as `{ /** the value to return */ x, ... }: x`.
- Some extensions to markdown are not yet supported, as you can see in the example above.

We'd like to acknowledge Yingchi Long for proposing a proof of concept for this functionality in [#9054](https://github.com/NixOS/nix/pull/9054), as well as @sternenseemann and Johannes Kirschbauer for their contributions, proposals, and their work on [RFC 145].

[RFC 145]: https://github.com/NixOS/rfcs/pull/145
62 changes: 62 additions & 0 deletions doc/manual/rl-next/shebang-relative.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
synopsis: "`nix-shell` shebang uses relative path"
prs:
- 5088
- 11058
issues:
- 4232
---

<!-- unfortunately no link target for the specific syntax -->
Relative [path](@docroot@/language/values.md#type-path) literals in `nix-shell` shebang scripts' options are now resolved relative to the [script's location](@docroot@/glossary?highlight=base%20directory#gloss-base-directory).
Previously they were resolved relative to the current working directory.

For example, consider the following script in `~/myproject/say-hi`:

```shell
#!/usr/bin/env nix-shell
#!nix-shell --expr 'import ./shell.nix'
#!nix-shell --arg toolset './greeting-tools.nix'
#!nix-shell -i bash
hello
```

Older versions of `nix-shell` would resolve `shell.nix` relative to the current working directory; home in this example:

```console
[hostname:~]$ ./myproject/say-hi
error:
… while calling the 'import' builtin
at «string»:1:2:
1| (import ./shell.nix)
| ^

error: path '/home/user/shell.nix' does not exist
```

Since this release, `nix-shell` resolves `shell.nix` relative to the script's location, and `~/myproject/shell.nix` is used.

```console
$ ./myproject/say-hi
Hello, world!
```

**Opt-out**

This is technically a breaking change, so we have added an option so you can adapt independently of your Nix update.
The old behavior can be opted into by setting the option [`nix-shell-shebang-arguments-relative-to-script`](@docroot@/command-ref/conf-file.md#conf-nix-shell-shebang-arguments-relative-to-script) to `false`.
This option will be removed in a future release.

**`nix` command shebang**

The experimental [`nix` command shebang](@docroot@/command-ref/new-cli/nix.md?highlight=shebang#shebang-interpreter) already behaves in this script-relative manner.

Example:

```shell
#!/usr/bin/env nix
#!nix develop
#!nix --expr ``import ./shell.nix``
#!nix -c bash
hello
```
2 changes: 1 addition & 1 deletion doc/manual/src/contributing/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ A environment variables that Google Test accepts are also worth knowing:
Putting the two together, one might run

```bash
GTEST_BREIF=1 GTEST_FILTER='ErrorTraceTest.*' meson test nix-expr-tests -v
GTEST_BRIEF=1 GTEST_FILTER='ErrorTraceTest.*' meson test nix-expr-tests -v
```

for short but comprensive output.
Expand Down
18 changes: 2 additions & 16 deletions doc/manual/src/language/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,13 @@ This section covers syntax and semantics of the Nix language.

### Path {#path-literal}

*Paths* are distinct from strings and can be expressed by path literals such as `./builder.sh`.

Paths are suitable for referring to local files, and are often preferable over strings.
- Path values do not contain trailing slashes, `.` and `..`, as they are resolved when evaluating a path literal.
- Path literals are automatically resolved relative to their [base directory](@docroot@/glossary.md#gloss-base-directory).
- The files referred to by path values are automatically copied into the Nix store when used in a string interpolation or concatenation.
- Tooling can recognize path literals and provide additional features, such as autocompletion, refactoring automation and jump-to-file.
*Paths* can be expressed by path literals such as `./builder.sh`.

A path literal must contain at least one slash to be recognised as such.
For instance, `builder.sh` is not a path:
it's parsed as an expression that selects the attribute `sh` from the variable `builder`.

Path literals are resolved relative to their [base directory](@docroot@/glossary.md#gloss-base-directory).
Path literals may also refer to absolute paths by starting with a slash.

> **Note**
Expand All @@ -215,15 +210,6 @@ This section covers syntax and semantics of the Nix language.
For example, `~/foo` would be equivalent to `/home/edolstra/foo` for a user whose home directory is `/home/edolstra`.
Path literals that start with `~` are not allowed in [pure](@docroot@/command-ref/conf-file.md#conf-pure-eval) evaluation.

Paths can be used in [string interpolation] and string concatenation.
For instance, evaluating `"${./foo.txt}"` will cause `foo.txt` from the same 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.
For example, assume you used a file path in an interpolated string during a `nix repl` session.
Later in the same session, after having changed the file contents, evaluating the interpolated string with the file path again might not return a new [store path], since Nix might not re-read the file contents. Use `:r` to reset the repl as needed.

[store path]: @docroot@/store/store-path.md

Path literals can also include [string interpolation], besides being [interpolated into other expressions].

[interpolated into other expressions]: ./string-interpolation.md#interpolated-expressions
Expand Down
31 changes: 30 additions & 1 deletion doc/manual/src/language/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,37 @@ The function [`builtins.isString`](builtins.md#builtins-isString) can be used to

### Path {#type-path}

<!-- TODO(@rhendric, #10970): Incorporate content from syntax.md#path-literal -->
A _path_ in the Nix language is an immutable, finite-length sequence of bytes starting with `/`, representing a POSIX-style, canonical file system path.
Path values are distinct from string values, even if they contain the same sequence of bytes.
Operations that produce paths will simplify the result as the standard C function [`realpath`] would, except that there is no symbolic link resolution.

[`realpath`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/realpath.html

Paths are suitable for referring to local files, and are often preferable over strings.
- Path values do not contain trailing or duplicate slashes, `.`, or `..`.
- Relative path literals are automatically resolved relative to their [base directory].
- Tooling can recognize path literals and provide additional features, such as autocompletion, refactoring automation and jump-to-file.

[base directory]: @docroot@/glossary.md#gloss-base-directory

A file is not required to exist at a given path in order for that path value to be valid, but a path that is converted to a string with [string interpolation] or [string-and-path concatenation] must resolve to a readable file or directory which will be copied into the Nix store.
For instance, evaluating `"${./foo.txt}"` will cause `foo.txt` from the same directory to be copied into the Nix store and result in the string `"/nix/store/<hash>-foo.txt"`.
Operations such as [`import`] can also expect a path to resolve to a readable file or directory.

[string interpolation]: string-interpolation.md#interpolated-expression
[string-and-path concatenation]: operators.md#string-and-path-concatenation
[`import`]: builtins.md#builtins-import

> **Note**
>
> 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.
> Later in the same session, after having changed the file contents, evaluating the interpolated string with the file path again might not return a new [store path], since Nix might not re-read the file contents.
> Use `:r` to reset the repl as needed.
[store path]: @docroot@/store/store-path.md

Path values can be expressed as [path literals](syntax.md#path-literal).
The function [`builtins.isPath`](builtins.md#builtins-isPath) can be used to determine if a value is a path.

### Null {#type-null}
Expand Down
26 changes: 26 additions & 0 deletions doc/manual/src/protocols/tarball-fetcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,30 @@ Link: <https://example.org/hello/442793d9ec0584f6a6e82fa253850c8085bb150a.tar.gz
For tarball flakes, the value of the `lastModified` flake attribute is
defined as the timestamp of the newest file inside the tarball.

## Gitea and Forgejo support

This protocol is supported by Gitea since v1.22.1 and by Forgejo since v7.0.4/v8.0.0 and can be used with the following flake URL schema:

```
https://<domain name>/<owner>/<repo>/archive/<reference or revison>.tar.gz
```

> **Example**
>
>
> ```nix
> # flake.nix
> {
> inputs = {
> foo.url = "https://gitea.example.org/some-person/some-flake/archive/main.tar.gz";
> bar.url = "https://gitea.example.org/some-other-person/other-flake/archive/442793d9ec0584f6a6e82fa253850c8085bb150a.tar.gz";
> qux = {
> url = "https://forgejo.example.org/another-person/some-non-flake-repo/archive/development.tar.gz";
> flake = false;
> };
> };
> outputs = { foo, bar, qux }: { /* ... */ };
> }
```
[Nix Archive]: @docroot@/store/file-system-object/content-address.md#serial-nix-archive
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@
++ pkgs.nixComponents.nix-external-api-docs.nativeBuildInputs
++ [
pkgs.buildPackages.cmake
pkgs.shellcheck
modular.pre-commit.settings.package
(pkgs.writeScriptBin "pre-commit-hooks-install"
modular.pre-commit.settings.installationScript)
Expand Down
3 changes: 1 addition & 2 deletions maintainers/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
''^src/libstore/common-protocol-impl\.hh$''
''^src/libstore/common-protocol\.cc$''
''^src/libstore/common-protocol\.hh$''
''^src/libstore/common-ssh-store-config\.hh$''
''^src/libstore/content-address\.cc$''
''^src/libstore/content-address\.hh$''
''^src/libstore/daemon\.cc$''
Expand Down Expand Up @@ -215,7 +216,6 @@
''^src/libstore/serve-protocol\.hh$''
''^src/libstore/sqlite\.cc$''
''^src/libstore/sqlite\.hh$''
''^src/libstore/ssh-store-config\.hh$''
''^src/libstore/ssh-store\.cc$''
''^src/libstore/ssh\.cc$''
''^src/libstore/ssh\.hh$''
Expand Down Expand Up @@ -495,7 +495,6 @@
excludes = [
# We haven't linted these files yet
''^config/install-sh$''
''^misc/systemv/nix-daemon$''
''^misc/bash/completion\.sh$''
''^misc/fish/completion\.fish$''
''^misc/zsh/completion\.zsh$''
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ subproject('external-api-docs')
subproject('libutil-c')
subproject('libstore-c')
subproject('libexpr-c')
subproject('libmain-c')

# Language Bindings
subproject('perl')
Expand Down
17 changes: 12 additions & 5 deletions misc/systemv/nix-daemon
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,28 @@ else
fi

# Source function library.
# shellcheck source=/dev/null
. /etc/init.d/functions

LOCKFILE=/var/lock/subsys/nix-daemon
RUNDIR=/var/run/nix
PIDFILE=${RUNDIR}/nix-daemon.pid
RETVAL=0

base=${0##*/}
# https://www.shellcheck.net/wiki/SC3004
# Check if gettext exists
if ! type gettext > /dev/null 2>&1
then
# If not, create a dummy function that returns the input verbatim
gettext() { printf '%s' "$1"; }
fi

start() {

mkdir -p ${RUNDIR}
chown ${NIX_DAEMON_USER}:${NIX_DAEMON_USER} ${RUNDIR}

echo -n $"Starting nix daemon... "
printf '%s' "$(gettext 'Starting nix daemon... ')"

daemonize -u $NIX_DAEMON_USER -p ${PIDFILE} $NIX_DAEMON_BIN $NIX_DAEMON_OPTS
RETVAL=$?
Expand All @@ -58,7 +65,7 @@ start() {
}

stop() {
echo -n $"Shutting down nix daemon: "
printf '%s' "$(gettext 'Shutting down nix daemon: ')"
killproc -p ${PIDFILE} $NIX_DAEMON_BIN
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f ${LOCKFILE} ${PIDFILE}
Expand All @@ -67,7 +74,7 @@ stop() {
}

reload() {
echo -n $"Reloading nix daemon... "
printf '%s' "$(gettext 'Reloading nix daemon... ')"
killproc -p ${PIDFILE} $NIX_DAEMON_BIN -HUP
RETVAL=$?
echo
Expand Down Expand Up @@ -105,7 +112,7 @@ case "$1" in
fi
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
printf '%s' "$(gettext "Usage: $0 {start|stop|status|restart|condrestart}")"
exit 2
;;
esac
Expand Down
1 change: 1 addition & 0 deletions packaging/components.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ in
nix-flake-tests = callPackage ../tests/unit/libflake/package.nix { };

nix-main = callPackage ../src/libmain/package.nix { };
nix-main-c = callPackage ../src/libmain-c/package.nix { };

nix-cmd = callPackage ../src/libcmd/package.nix { };

Expand Down
17 changes: 17 additions & 0 deletions packaging/dependencies.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,28 @@
versionSuffix,
}:

let
prevStdenv = stdenv;
in

let
inherit (pkgs) lib;

root = ../.;

stdenv = if prevStdenv.isDarwin && prevStdenv.isx86_64
then darwinStdenv
else prevStdenv;

# Fix the following error with the default x86_64-darwin SDK:
#
# error: aligned allocation function of type 'void *(std::size_t, std::align_val_t)' is only available on macOS 10.13 or newer
#
# Despite the use of the 10.13 deployment target here, the aligned
# allocation function Clang uses with this setting actually works
# all the way back to 10.6.
darwinStdenv = pkgs.overrideSDK prevStdenv { darwinMinVersion = "10.13"; };

# Nixpkgs implements this by returning a subpath into the fetched Nix sources.
resolvePath = p: p;

Expand Down
1 change: 1 addition & 0 deletions packaging/hydra.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ let
"nix-flake"
"nix-flake-tests"
"nix-main"
"nix-main-c"
"nix-cmd"
"nix-ng"
];
Expand Down
2 changes: 2 additions & 0 deletions src/build-remote/build-remote.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

#include "machines.hh"
#include "shared.hh"
#include "plugin.hh"
#include "pathlocks.hh"
#include "globals.hh"
#include "serialise.hh"
#include "build-result.hh"
#include "store-api.hh"
#include "strings.hh"
#include "derivations.hh"
#include "local-store.hh"
#include "legacy.hh"
Expand Down
Loading

0 comments on commit 3426e54

Please sign in to comment.