1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-12 13:36:02 +01:00
Commit graph

7208 commits

Author SHA1 Message Date
regnat
ddbb122df1 testS: poll more eagerly for the daemon start/stop
Polling every 1 second means that even the simplest test takes at least
2 seconds. We can reasonably poll 1/10 of that to make things much
  quicker (esp. given that most of the time 0.1s is enough for the
  daemon to be started or stopped)

(cherry picked from commit 9c470cb969)
2025-02-14 01:26:27 -05:00
Théophane Hufschmitt
196670af76 Don't run the tests that require building if we're not building
A couple of tests require building some libraries that depend on Nix,
and assume it to be built locally.
Don't run these if we only want to run the install tests.

This prevents the CI from rebuilding several times Nix (like in
https://github.com/NixOS/nix/actions/runs/6404422275/job/17384964033#step:6:6412), thus removing a fair amount of build time.

(cherry picked from commit eb68454be6)
2025-02-14 01:26:27 -05:00
John Ericson
e813f9c4cd Add self-version daemon test
This is not a cherry-pick because enough reworking had to happen.
2025-02-14 00:57:56 -05:00
John Ericson
67ab776e15 Harden tests' bash
Use `set -u` and `set -o pipefail` to catch accidental mistakes and
failures more strongly.

 - `set -u` catches the use of undefined variables
 - `set -o pipefail` catches failures (like `set -e`) earlier in the
   pipeline.

This makes the tests a bit more robust. It is nice to read code not
worrying about these spurious success paths (via uncaught) errors
undermining the tests. Indeed, I caught some bugs doing this.

There are a few tests where we run a command that should fail, and then
search its output to make sure the failure message is one that we
expect. Before, since the `grep` was the last command in the pipeline
the exit code of those failing programs was silently ignored. Now with
`set -o pipefail` it won't be, and we have to do something so the
expected failure doesn't accidentally fail the test.

To do that we use `expect` and a new `expectStderr` to check for the
exact failing exit code. See the comments on each for why.

`grep -q` is replaced with `grepQuiet`, see the comments on that
function for why.

`grep -v` when we just want the exit code is replaced with `grepInverse,
see the comments on that function for why.

`grep -q -v` together is, surprise surprise, replaced with
`grepQuietInverse`, which is both combined.

(cherry picked from commit c11836126b)
2025-02-13 11:36:30 -05:00
John Ericson
5e13c907b4 Make init.sh safe to run twice
(cherry picked from commit 5dbbf23332)
2025-02-13 11:36:30 -05:00
Andrea Ciceri
51b03401fb Tighten up the exportReferencesGraph tests
Add an `$` at the end of the `grep` regex. Without it, `checkRef foo`
would always imply `checkRef foo.drv`. We want to tell these situations
apart to more precisely test what is going on.

(cherry picked from commit f58759816d)
2025-02-13 11:36:30 -05:00
Robert Hensing
0a53374a4b tests: Add command source locations to test log
(cherry picked from commit 9813e54a74)
2025-02-13 11:36:30 -05:00
John Ericson
ac295a5f33 Flip condition on daemon version for structured attrs
We want the old behavior, since this is Nix 2.3.
2025-02-13 11:36:30 -05:00
John Ericson
7358292924 Fix testing the other daemon
The eventual PATH entry needs the `.../bin` or we will not use the right
daemon.

(cherry picked from commit 06fb6aecea)
2025-02-13 11:36:30 -05:00
regnat
918861b196 Make the post-build-hook use the daemon Nix package
Having the `post-build-hook` use `nix` from the client package can lead
to a deadlock in case there’s a db migration to do between both, as a
`nix` command running inside the hook will run as root (and as such will
bypass the daemon), so might trigger a db migration, which will get
stuck trying to get a global lock on the DB (as the daemon that ran the
hook already has a lock on it).

(cherry picked from commit 93eadd5803)
2025-02-13 11:36:30 -05:00
regnat
5d324b2d0a Fix the isDaemonNewer check
- Don’t hardcode the “newer” version
- Remove an ill-placed `return`

(cherry picked from commit 3a2fc9ce1d)
2025-02-13 11:36:30 -05:00
Sergei Trofimovich
c239a1652e mk/tests.mk: document 'installcheck' in 'make help'
(cherry picked from commit 1e6faa7d06)
2025-02-13 11:36:30 -05:00
regnat
6e595ff55f Remove the right socket before starting the daemon
For some reason, an old socket occasionally stays here on OSX, causing
the subsequent tests to fail

(cherry picked from commit c2c0dba792)
2025-02-13 11:36:30 -05:00
regnat
c434a11a04 Allow running all the tests with the daemon
When `NIX_DAEMON_PACKAGE` is set, make all the tests use the Nix daemon.
That way we can test every piece of Nix functionality both with and
without the daemon.

Tests for which using the daemon isn’t possible or doesn’t make sens can
selectively be disabled with `needLocalStore`

(cherry picked from commit addacfce4a)
2025-02-13 11:36:30 -05:00
regnat
62a42ab43e Make the tests (optionnally) run in another derivation
That way we can run them without rebuilding Nix

(cherry picked from commit a0866c8ea4)
2025-02-13 11:36:30 -05:00
regnat
02a186883b Add a test ensuring compatibility with an old daemon
This requires adding `nix` to its own closure which is a bit unfortunate,
but as it is optional (the test will be disabled if `OUTER_NIX` is unset) it
shouldn't be too much of an issue.

(Ideally this should go in another derivation so that we can build Nix and run
the test independently, but as the tests are running in the same derivation
as the build it's a bit complicated to do so).

(cherry picked from commit 5716345adf)
2025-02-13 11:36:30 -05:00
regnat
e0e9f91049 Actually test nix-env with a remote store
The `remote-store` test loads the `user-env` one to test nix-env when
using the daemon, but actually does it incorrectly because every test
starts (in `common.sh`) by resetting the value of `NIX_REMOTE`, meaning
that the `user-env` test will never use the daemon.

Fix this by setting `NIX_REMOTE_` before sourcing `user-env.sh` in the
`remote-store` test, so that `NIX_REMOTE` is correctly set inside the
test

(cherry picked from commit f6ac888d3e)
2025-02-13 11:36:30 -05:00
John Ericson
fd753efe17
Merge pull request #9495 from NixOS/2.3-macos-eof
[Backport 2.3-maintainence] Fix "unexpected EOF" errors on macOS
2025-02-13 11:35:45 -05:00
Eelco Dolstra
5fca88973f Open slave pseudoterminal before CLONE_NEWUSER
Otherwise, when running as root and user namespaces are enabled,
opening the slave fails with EPERM.

Fixes "opening pseudoterminal slave: Permission denied" followed by a
hang (https://hydra.nixos.org/build/213104244), and "error: getting
sandbox mount namespace: No such file or directory" (#8072), which
happens when the child fails very quickly and consequently reading
/proc/<child>/ns fails.

(cherry picked from commit 16db8dc96f)
2025-02-13 11:21:42 -05:00
Eelco Dolstra
94eba8a85a Change builderOut from Pipe to AutoCloseFD
(cherry picked from commit 6029c763c2)
2025-02-13 11:21:42 -05:00
Eelco Dolstra
6613e7ebfb Move pseudoterminal slave open to child
Hopefully this fixes "unexpected EOF" failures on macOS
(#3137, #3605, #7242, #7702).

The problem appears to be that under some circumstances, macOS
discards the output written to the slave side of the
pseudoterminal. Hence the parent never sees the "sandbox initialized"
message from the child, even though it succeeded. The conditions are:

* The child finishes very quickly. That's why this bug is likely to
  trigger in nix-env tests, since that uses a builtin builder. Adding
  a short sleep before the child exits makes the problem go away.

* The parent has closed its duplicate of the slave file
  descriptor. This shouldn't matter, since the child has a duplicate
  as well, but it does. E.g. moving the close to the bottom of
  startBuilder() makes the problem go away. However, that's not a
  solution because it would make Nix hang if the child dies before
  sending the "sandbox initialized" message.

* The system is under high load. E.g. "make installcheck -j16" makes
  the issue pretty reproducible, while it's very rare under "make
  installcheck -j1".

As a fix/workaround, we now open the pseudoterminal slave in the
child, rather than the parent. This removes the second condition
(i.e. the parent no longer needs to close the slave fd) and I haven't
been able to reproduce the "unexpected EOF" with this.

(cherry picked from commit c536e00c9d)
2025-02-13 11:21:42 -05:00
Eelco Dolstra
3a82f6a117 Simplify commonChildInit()
(cherry picked from commit 19326ac297)
2025-02-13 11:21:42 -05:00
John Ericson
3468fec15b
Merge pull request #12467 from NixOS/modernize-gha-2.3
[Nix 2.3] Reconcile GitHub Actions with master
2025-02-13 11:20:47 -05:00
John Ericson
4a18760022 Remove installer and installer_test GHAs for now
We never got them set up, as evidenced by missing script.
2025-02-13 11:11:37 -05:00
John Ericson
6c5089550e Reconcile GitHub Actions with master
Roughty matches as of 9f2b9256b6.

Hopefully this makes CI work again.
2025-02-13 10:54:04 -05:00
Eelco Dolstra
ff8cce1244
Merge pull request #12026 from Ma27/2.3-backport-structured-attrs-env
[2.3] build: backport NIX_ATTRS_*_FILE
2024-12-09 13:03:10 +01:00
Maximilian Bosch
0c5333a4f6
build: backport NIX_ATTRS_*_FILE
This was originally added in #4770 to support structured attrs in
`nix-shell` & `nix develop`: the issue was that it was somewhat awkward
to just write those files into a project directory, especially since
it'd break in case of multiple `nix-shell` invocations from the same
directory. Now the files are written to another, temporary
location when using `nix-shell`/`nix develop` and the correct path is
referenced by NIX_ATTRS_*_FILE.

In `nixpkgs`, it's now common to use these environment variables,
however we still fall back to checking to `.attrs.sh` & `.attrs.json`
since the minimum Nix version we support is 2.3.17[1] which doesn't have
this change.

This however makes implementing structured attrs support more
complicated than needed[2] and in fact we have a few places where the
check for `.attrs.sh`/`.attrs.json` isn't made, so these only break with
Nix 2.3[3].

The idea is now to

* get this into 2.3.18
* bump minver once again to 2.3.18 in nixpkgs
* remove all occurrences of `.attrs.sh`/`.attrs.json` from nixpkgs.

[1] f4bd97b8fa/lib/minver.nix
[2] https://github.com/NixOS/nixpkgs/pull/357053/files#diff-791a01ef89c157eb74d9c87ab8cbc3b81e2cf082cab70b8fec3472cd75ce860dR3-R5
[3] https://github.com/NixOS/nixpkgs/pull/357053#discussion_r1857362490
2024-12-08 15:45:05 +01:00
Eelco Dolstra
99f14d4b34 Revert "tests/check.sh: Fix a race"
This reverts commit 0776aa11c9 because
it's causing a test failure: https://hydra.nixos.org/build/247889890
2024-03-07 14:27:23 +01:00
Eelco Dolstra
b4d5aaca60
Merge pull request from GHSA-2ffj-w4mj-pg37
Sandbox escape 2.3
2024-03-07 11:56:24 +01:00
Théophane Hufschmitt
8604f6d329 Add release notes 2024-03-01 10:24:54 +01:00
Théophane Hufschmitt
2064277b05 Fix a typo in a test comment
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2024-03-01 10:24:54 +01:00
Théophane Hufschmitt
8c27eb6c1b Copy the output of fixed-output derivations before registering them
It is possible to exfiltrate a file descriptor out of the build sandbox
of FODs, and use it to modify the store path after it has been
registered.
To avoid that issue, don't register the output of the build, but a copy
of it (that will be free of any leaked file descriptor).
2024-03-01 10:24:54 +01:00
Théophane Hufschmitt
9c0be4c156 Add a NixOS test for the sandbox escape
Test that we can't leverage abstract unix domain sockets to leak file
descriptors out of the sandbox and modify the path after it has been
registered.
2024-03-01 10:24:54 +01:00
Théophane Hufschmitt
ec26251bb9
Merge pull request #9771 from hercules-ci/2.3-flake
[2.3] Add flake for testing purposes
2024-01-26 09:41:25 +01:00
Robert Hensing
0776aa11c9 tests/check.sh: Fix a race
Based on 02dd6bb610
2024-01-15 11:40:53 +01:00
Robert Hensing
0099f8e8de Add best-effort flake.nix
The purpose for this flake is to make `nix run nix/2.3-maintenance` work,
so that it's easier to answer questions about this old series of releases.
2024-01-15 10:40:48 +01:00
Eelco Dolstra
575859a535 Bump version 2023-11-03 18:05:47 +01:00
John Ericson
f76990444c
Merge pull request #9261 from flokli/backport-3564
[2.3-maintenance] Wait for build users when none are available
2023-11-01 20:01:36 -04:00
Eelco Dolstra
791af78365
Merge pull request #9263 from flokli/update-stringly-typed-configureflags
[2.3-maintenance] Convert stringly-typed configureFlags to lists of strings
2023-10-31 16:06:52 +01:00
Eelco Dolstra
5757632bcb
Merge pull request #9260 from flokli/backport-4012
[2.3-maintenance] Escape `${` in strings when printing Nix expressions
2023-10-31 16:06:07 +01:00
Eelco Dolstra
78d73112a6
Merge pull request #9262 from flokli/pkg-config-rename
[2.3-maintenance] Address removal of pkgconfig alias
2023-10-31 16:05:34 +01:00
sternenseemann
a4cafa65e7 Convert stringly-typed configureFlags to lists of strings
This has been deprecated in nixpkgs and the warning resulting from that
is driving me crazy.
2023-10-31 12:25:06 +02:00
sternenseemann
6663e7aeea Address removal of pkgconfig alias
nixpkgs ended up removing that alias, this fixes the build with a more
recent nixpkgs.
2023-10-31 12:22:36 +02:00
Alexander Bantyev
12935e54ea Mention build users in the 'waiting for' message
(cherry picked from commit 772e5db828)
2023-10-31 12:15:35 +02:00
Alexander Bantyev
849f9b83a8 Don't block while waiting for build users
(cherry picked from commit 14073fb76b)
2023-10-31 12:15:35 +02:00
Alexander Bantyev
a1469cc8f4 Wait for build users when none are available
(cherry picked from commit 880a62b08443a6baa55dab027b69bb8b1551a588)
2023-10-31 12:15:35 +02:00
regnat
b2463d649c Escape ${ in strings when printing Nix expressions
Otherwise the result of the printing can't be parsed back correctly by
Nix (because the unescaped `${` will be parsed as the begining of an
anti-quotation).

Fix #3989

(cherry picked from commit 250f8a4bba)
2023-10-31 12:06:50 +02:00
Eelco Dolstra
63ba2fde50
Merge pull request #9245 from bjornfor/backport-installer-fix
[2.3] Backport installer fix for non-NixOS
2023-10-27 16:28:07 +02:00
John Ericson
619e9758bb
Merge pull request #4593 from grahamc/builder-host-key-stable
(Backport #4574) distributed builds: load remote builder host key from the machines file
2023-10-26 16:19:06 -04:00
John Ericson
b4abe56a23 Merge remote-tracking branch 'upstream/2.3-maintenance' into builder-host-key-stable 2023-10-26 16:01:18 -04:00