1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-06 00:51:47 +02:00
Commit graph

4916 commits

Author SHA1 Message Date
John Ericson
52d2ad1de1
Merge a55806a0dd into 448cfb71ea 2025-06-24 14:06:48 +00:00
Eelco Dolstra
37685b1c9c Fix Darwin test failure in repl.sh
Fixes

  error:
         … while processing sandbox path '/private/tmp/nix-shell.0MDgyx/nix-test/ca/repl/store/nix/var/nix/builds/nix-build-simple.drv-65916-3910734210' (/private/tmp/nix-shell.0MDgyx/nix-test/ca/repl/store)

         error: 'nix' is too short to be a valid store path

which happened because we were now putting the build directory
underneath the store directory.
2025-06-22 16:49:44 +02:00
Eelco Dolstra
2e2fe4cb07 Cleanup 2025-06-22 16:49:44 +02:00
Eelco Dolstra
5acf50a327 Disallow the build directory having world-writable parents 2025-06-22 16:49:44 +02:00
eldritch horrors
88b7db1ba4 libstore: Don't default build-dir to temp-dir, store setting
If a build directory is accessible to other users it is possible to
smuggle data in and out of build directories. Usually this is only
a build purity problem, but in combination with other issues it can
be used to break out of a build sandbox. to prevent this we default
to using a subdirectory of nixStateDir (which is more restrictive).

(cherry picked from pennae Lix commit 55b416f6897fb0d8a9315a530a9b7f0914458ded)
(store setting done by roberth)
2025-06-22 16:49:44 +02:00
Eelco Dolstra
9af4c267c6 Chown structured attr files safely 2025-06-22 16:48:34 +02:00
Eelco Dolstra
a4b5584fb1 Replace 'bool sync' with an enum for clarity
And drop writeFileAndSync().
2025-06-22 16:48:34 +02:00
Eelco Dolstra
479c356510 Drop guessOrInventPathFromFD()
No need to do hacky stuff like that when we already know the original path.
2025-06-22 16:48:34 +02:00
Eelco Dolstra
e5dc3e84f0 Tweak comment 2025-06-22 16:48:34 +02:00
Raito Bezarius
4ea4813753 libstore: ensure that temporary directory is always 0o000 before deletion
In the case the deletion fails, we should ensure that the temporary
directory cannot be used for nefarious purposes.

Change-Id: I498a2dd0999a74195d13642f44a5de1e69d46120
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-22 16:48:33 +02:00
Raito Bezarius
4e59d3fdb2 libstore: ensure that passAsFile is created in the original temp dir
This ensures that `passAsFile` data is created inside the expected
temporary build directory by `openat()` from the parent directory file
descriptor.

This avoids a TOCTOU which is part of the attack chain of CVE-????.

Change-Id: Ie5273446c4a19403088d0389ae8e3f473af8879a
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-22 16:48:33 +02:00
Raito Bezarius
034f59bbb9 libutil: writeFile variant for file descriptors
`writeFile` lose its `sync` boolean flag to make things simpler.

A new `writeFileAndSync` function is created and all call sites are
converted to it.

Change-Id: Ib871a5283a9c047db1e4fe48a241506e4aab9192
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-22 16:48:33 +02:00
Raito Bezarius
002d202653 libstore: chown to builder variant for file descriptors
We use it immediately for the build temporary directory.

Change-Id: I180193c63a2b98721f5fb8e542c4e39c099bb947
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-22 16:48:33 +02:00
Raito Bezarius
6a5b6ad3b7 libstore: open build directory as a dirfd as well
We now keep around a proper AutoCloseFD around the temporary directory
which we plan to use for openat operations and avoiding the build
directory being swapped out while we are doing something else.

Change-Id: I18d387b0f123ebf2d20c6405cd47ebadc5505f2a
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-22 16:48:33 +02:00
John Ericson
a55806a0dd Get rid of addWantedOutputs
This is just a code cleanup; it should not be behavior change.

`addWantedOutputs` is removed by introducing `DerivationTrampolineGoal`.

`DerivationGoal` now only tracks a single output, and is back to
tracking a plain store path `drvPath`, not a deriving path one. Its
`addWantedOutputs` method is gone. These changes will allow subsequent
PRs to simplify it greatly.

Because the purpose of each goal is back to being immutable, we can also
once again make `Goal::buildResult` a public field, and get rid of the
`getBuildResult` method. This simplifies things also.

`DerivationTrampolineGoal` is, as the nane is supposed to indicate, a
cheap "trampoline" goal. It takes immutable sets of wanted outputs, and
just kicks of `DerivationGoal`s for them. Since now "actual work" is
done in these goals, it is not wasteful to have separate ones for
separate sets of outputs, even if those outputs (and the derivations
they are from) overlap.

This design is described in more detail in the doc comments on the goal
types, which I've now greatly expanded.

---

This separation of concerns will make it possible for future work on
issues like #11928, and to continue the path of having more goal types,
but each goal type does fewer things (issue #12628).

---

This commit in some sense reverts
f4f28cdd0e, but that one kept around
`addWantedOutputs`. I am quite sure it was having two layers of goals
with `addWantedOutputs` that caused the issues --- restarting logic like
`addWantedOutputs` has is very tempermental! In this version of the
change, we have *zero* layers of `addWantedOutputs` --- no goal type
needs it, or otherwise has a mutable objective --- and so I think this
change is safe.

Co-authored-by: Sergei Zimmerman <145775305+xokdvium@users.noreply.github.com>
2025-06-20 18:43:35 -04:00
Sergei Zimmerman
6ef683cb2a
Restore multiline formatting of lists in meson files
Applies a workaround to enforce multiline formatting
of lists to reduce code churn introduced in 93a42a5971.
2025-06-20 23:12:36 +03:00
Luc Perkins
9c120596ec
Merge remote-tracking branch 'upstream/master' into messages-present-tense 2025-06-19 10:51:50 -07:00
Eelco Dolstra
20ba6be749 Improve the Rosetta installation hint
The Nix daemon detects supported system types at start time, so it
needs to be restarted to detect x86_64-darwin support.
2025-06-19 13:58:51 +02:00
John Ericson
d254c840b5
Merge pull request #13349 from obsidiansystems/structured-attrs-json
Introduce top-level `structuredAttrs` field in JSON derivation format
2025-06-18 16:35:42 -04:00
Luc Perkins
d6710b4c04
Merge remote-tracking branch 'upstream/master' into messages-present-tense 2025-06-18 08:24:23 -07:00
Wolfgang Walther
d64c922164
libstore: fix race condition when creating state directories
Running parallel nix in nix can lead to multiple instances trying to
create the state directories and failing on the `createSymlink` step,
because the link already exists.

`replaceSymlink` is already idempotent, so let's use that.

Resolves #2706
2025-06-17 08:45:29 +02:00
John Ericson
f8c1ac9515 Introduce top-level structuredAttrs field in JSON derivation format
Makes the behavoral change of #13263 without the underlying refactor.
Hopefully this clearly safe from a perf and GC perspective, and will
make it easier to benchmark #13263.
2025-06-12 20:45:47 -04:00
Luc Perkins
ab10fddc6e
Rework future tense in user-facing messages 2025-06-12 09:07:36 -07:00
Sergei Zimmerman
93a42a5971
flake: Add meson formatter
This adds a meson.format file that mostly mirrors the projects
meson style and a pre-commit hook to enforce this style.
Some low-diff files are formatted.
2025-06-11 22:08:03 +00:00
John Ericson
371fcf91c3
Merge pull request #13294 from obsidiansystems/fix-13293
Fix #13293
2025-06-11 16:55:43 -04:00
John Ericson
5267718472 Fix #13293
We move the `assertPathValidity` to where we know what the wanted
outputs are.
2025-06-11 16:15:26 -04:00
Luc Perkins
525078c59d
Fix broken link in configuration description 2025-06-11 08:52:04 -07:00
Eelco Dolstra
908129eb22 Cleanup 2025-05-30 11:54:54 +02:00
Eelco Dolstra
4dc419eaec Split LinuxDerivationBuilder
This restores doing seccomp/personality initialization even when
sandboxing is disabled.

https://hydra.nixos.org/build/298482132
2025-05-29 21:57:25 +02:00
Eelco Dolstra
b7fd872147 Cleanup 2025-05-29 21:39:22 +02:00
John Ericson
24f5d7a9c3 Fix warning when HAVE_EMBEDDED_SANDBOX_SHELL is not set
Clang doesn't like the double indent that is needed for the `if...else`
that is CPP'd away. Adding braces is fine in the `if...else...` case,
and fine as a naked block in the CPP'd away case, and properly-indented
both ways.
2025-05-28 12:49:13 -04:00
John Ericson
625dce659a Prepare for FreeBSD sandboxing support
This is the utility changes from #9968, which were easier to rebase
first.

I (@Ericson2314) didn't write this code; I just rebased it.

Co-Authored-By: Artemis Tosini <me@artem.ist>
Co-Authored-By: Audrey Dutcher <audrey@rhelmot.io>
2025-05-27 14:54:50 -04:00
John Ericson
653a93ac0f
Merge pull request #13276 from NixOS/split-derivation-builder
Move platform-specific code out of `DerivationBuilder`
2025-05-27 13:39:02 -04:00
Eelco Dolstra
cf9d962086 Remove unused variable 2025-05-27 17:54:02 +02:00
Eelco Dolstra
f9fdf94e12 Fix macOS build 2025-05-27 15:25:51 +02:00
gustavderdrache
b04962b33b Make platform checks throw BuildError like other failures
Co-authored-by: Cole Helbling <cole.e.helbling@outlook.com>
2025-05-27 08:57:13 -04:00
Eelco Dolstra
352ca238a9 Move cgroup support 2025-05-27 14:06:32 +02:00
Eelco Dolstra
b27e684ca5 Inline initTmpDir() 2025-05-27 14:00:28 +02:00
Eelco Dolstra
774678b87f Get rid of tmpDirInSandbox variable 2025-05-27 14:00:21 +02:00
Eelco Dolstra
c9b55fa3f0 Move autoDelChroot 2025-05-27 14:00:16 +02:00
Eelco Dolstra
9e2151d839 Move seccomp code 2025-05-27 14:00:12 +02:00
Eelco Dolstra
b623fe8d14 Move doBind() 2025-05-27 14:00:07 +02:00
Eelco Dolstra
9f8f3968e3 Eliminate useChroot 2025-05-27 13:59:40 +02:00
Eelco Dolstra
67408807d8 Move pathsInChroot 2025-05-27 13:57:41 +02:00
Eelco Dolstra
5653bf5e0a DerivationBuilder: Move Linux/Darwin-specific code into subclasses 2025-05-27 13:42:22 +02:00
Eelco Dolstra
aaca9711fc DerivationBuilderImpl: Drop std::optional from derivationType
No point in computing this lazily, since it's pretty much the first
thing the DerivationBuilder does.
2025-05-27 09:04:29 +02:00
Eelco Dolstra
93ae95be83 Remove duplicate comments on DerivationBuilderImpl overriden methods
Having the exact same doc comments isn't very useful/maintainable.
2025-05-26 16:05:54 +02:00
Eelco Dolstra
69914e4b3c Remove buildUser from DerivationBuilder
The use of a `buildUser` is an implementation detail of some types of
sandboxes that shouldn't exposed.
2025-05-26 16:05:35 +02:00
Sergei Zimmerman
114de63d88
Fix various typos in source code
This only touches code comments, class names, documentation,
enumeration names and tests.
2025-05-25 20:14:11 +00:00
Eelco Dolstra
d877b0c0cc fromStructuredAttrs(): Don't crash if exportReferencesGraph is a string
Fixes

  error: [json.exception.type_error.302] type must be array, but is string

and other crashes.

Fixes #13254.
2025-05-24 00:17:03 +02:00