aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/build
AgeCommit message (Collapse)Author
2024-05-29util.{hh,cc}: Split out file-system.{hh,cc}Tom Hubrecht
Change-Id: Ifa89a529e7e34e7291eca87d802d2f569cf2493e
2024-05-26worker: process timeouts first, and exclusivelyeldritch horrors
check goals for timeouts first, and their activity fds only if no timeout has occurred. checking for timeouts *after* activity sets us up for assertion failures by running multiple build completion notifiers, the first of which will kill/reap the the goal process and consuming the Pid instance. when the second notifier attempts to do the same it will core dump with an assertion failure in Pid and take down not only the single goal, but the entire daemon and all goals it was building. luckily this is rare in practice since it requires a build to both finish and time out at the same time. writing a test for this is not feasible due to how much it relies on scheduling to actually trigger the underlying bug, but on idle machines it can usually be triggered by running multiple sleeping builds with timeout set to the sleep duration and `--keep-going`: nix-build --timeout 10 --builders '' --keep-going -E ' with import <nixpkgs> {}; builtins.genList (i: runCommand "foo-${toString i}" {} "sleep 10") 100 ' Change-Id: I394d36b2e5ffb909cf8a19977d569bbdb71cb67b
2024-05-25libstore: remove duplicate builder variableArtemis Tosini
The `builder` local variable and duplicate `args.push_back` are no longer required since the Darwin sandbox stopped using `sandbox-exec`. The `drv->isBuiltin` check is not required either, as args are not accessed when the builder is builtin. Change-Id: I80b939bbd6f727b01793809921810ff09b579d54
2024-05-24libstore/build: always enable seccomp filtering and no-new-privilegesAlois Wohlschlager
Seccomp filtering and the no-new-privileges functionality improve the security of the sandbox, and have been enabled by default for a long time. In https://git.lix.systems/lix-project/lix/issues/265 it was decided that they should be enabled unconditionally. Accordingly, remove the allow-new-privileges (which had weird behavior anyway) and filter-syscall settings, and force the security features on. Syscall filtering can still be enabled at build time to support building on architectures libseccomp doesn't support. Change-Id: Iedbfa18d720ae557dee07a24f69b2520f30119cb
2024-05-19libutil: Create chmodPath functionArtemis Tosini
Move the identical static `chmod_` functions in libstore to libutil. the function is called `chmodPath` instead of `chmod` as otherwise it will shadow the standard library chmod in the nix namespace, which is somewhat confusing. Change-Id: I7b5ce379c6c602e3d3a1bbc49dbb70b1ae8f7bad
2024-05-16Allow enabling core dumps from builds for nix & child processesmidnightveil
Fixes https://git.lix.systems/lix-project/lix/issues/268 Change-Id: I3f1b0ddf064f891cca8b53229c5c31c74cea3d9f
2024-05-12Merge "libstore: Fix sandbox=relaxed" into mainArtemis Tosini
2024-05-10libutil: remove callback.hheldritch horrors
it's no longer used. it really shouldn't have existed this long since it was just a mashup of both std::promise and std::packaged_task in a shape that makes composition unnecessarily difficult. all but a single case of Callback pattern calls were fully synchronous anyway, and even this sole outlier was by far not important enough to justify the extra complexity. Change-Id: I208aec4572bf2501cdbd0f331f27d505fca3a62f
2024-05-09libstore: un-callback-ify Store::queryRealisationUncachedeldritch horrors
Change-Id: I4a328f46eaac3bb8b19ddc091306de83348be9cf
2024-05-09libstore: de-callback-ify Store::queryPathInfoUncachedeldritch horrors
Change-Id: I23a156aaff5328f67ca16ccd85c0ea1711b21e35
2024-05-09libstore: de-callback-ify CA realisation substitutioneldritch horrors
this is the *only* real user of file transfer download completion callbacks, and a pretty spurious user at that (seeing how nothing here is even turned on by default and indeed a dependency of path substitution which *isn't* async, and concurrency-limited). it'll be a real pain to keep this around, and realistically it would be a lot better to overhaul substitution in general to be *actually* async. that requires a proper async framework footing though, and we don't have anything of the sort, but it's also blocking *that* Change-Id: I1bf671f217c654a67377087607bf608728cbfc83
2024-05-08libstore: Fix sandbox=relaxedThéophane Hufschmitt
The fix for the Darwin vulnerability in ecdbc3b207eaec1a2cafd2a0d494bcbabdd60a11 also broke setting `__sandboxProfile` when `sandbox=relaxed` or `sandbox=false`. This cppnix change fixes `sandbox=relaxed` and adds a suitable test. Co-Authored-By: Artemis Tosini <lix@artem.ist> Co-Authored-By: Eelco Dolstra <edolstra@gmail.com> Change-Id: I40190f44f3e1d61846df1c7b89677c20a1488522
2024-05-07libstore: limit CA realisation info substitution concurrencyeldritch horrors
this seems to be an oversight, considering that regular substitutions are concurrency-limited. while not particularly necessary at present, once we've removed the `Callback` based interfaces it will be needed. Change-Id: Ide2d08169fcc24752cbd07a1d33fb8482f7034f5
2024-05-04Fix /etc/group having desynced IDs from the actual UID in the sandboxJade Lovelace
This was found when `logrotate.conf` failed to build in a NixOS system with: /nix/store/26zdl4pyw5qazppj8if5lm8bjzxlc07l-coreutils-9.3/bin/id: cannot find name for group ID 30000 This was surprising because it seemed to mean that /etc/group was busted in the sandbox. Indeed it was: root:x:0: nixbld:!:100: nogroup:x:65534: We diagnosed this to sandboxUid() being called before usingUserNamespace() was called, in setting up /etc/group inside the sandbox. This code desperately needs refactoring. We also moved the /etc/group code to be with the /etc/passwd code, but honestly this code is all spaghetti'd all over the place and needs some more serious tidying than we did here. We also moved some checks to be earlier to improve locality with where the things they are checking come from. Change-Id: Ie29798771f3593c46ec313a32960fa955054aceb
2024-05-04Merge "libstore/local-derivation-goal: prohibit creating setuid/setgid ↵Maximilian Bosch
binaries" into main
2024-05-03libstore/local-derivation-goal: prohibit creating setuid/setgid binariesMaximilian Bosch
With Linux kernel >=6.6 & glibc 2.39 a `fchmodat2(2)` is available that isn't filtered away by the libseccomp sandbox. Being able to use this to bypass that restriction has surprising results for some builds such as lxc[1]: > With kernel ≥6.6 and glibc 2.39, lxc's install phase uses fchmodat2, > which slips through https://github.com/NixOS/nix/blob/9b88e5284608116b7db0dbd3d5dd7a33b90d52d7/src/libstore/build/local-derivation-goal.cc#L1650-L1663. > The fixupPhase then uses fchmodat, which fails. > With older kernel or glibc, setting the suid bit fails in the > install phase, which is not treated as fatal, and then the > fixup phase does not try to set it again. Please note that there are still ways to bypass this sandbox[2] and this is mostly a fix for the breaking builds. This change works by creating a syscall filter for the `fchmodat2` syscall (number 452 on most systems). The problem is that glibc 2.39 is needed to have the correct syscall number available via `__NR_fchmodat2` / `__SNR_fchmodat2`, but this flake is still on nixpkgs 23.11. To have this change everywhere and not dependent on the glibc this package is built against, I added a header "fchmodat2-compat.hh" that sets the syscall number based on the architecture. On most platforms its 452 according to glibc with a few exceptions: $ rg --pcre2 'define __NR_fchmodat2 (?!452)' sysdeps/unix/sysv/linux/x86_64/x32/arch-syscall.h 58:#define __NR_fchmodat2 1073742276 sysdeps/unix/sysv/linux/mips/mips64/n32/arch-syscall.h 67:#define __NR_fchmodat2 6452 sysdeps/unix/sysv/linux/mips/mips64/n64/arch-syscall.h 62:#define __NR_fchmodat2 5452 sysdeps/unix/sysv/linux/mips/mips32/arch-syscall.h 70:#define __NR_fchmodat2 4452 sysdeps/unix/sysv/linux/alpha/arch-syscall.h 59:#define __NR_fchmodat2 562 I added a small regression-test to the setuid integration-test that attempts to set the suid bit on a file using the fchmodat2 syscall. I confirmed that the test fails without the change in local-derivation-goal. Additionally, we require libseccomp 2.5.5 or greater now: as it turns out, libseccomp maintains an internal syscall table and validates each rule against it. This means that when using libseccomp 2.5.4 or older, one may pass `452` as syscall number against it, but since it doesn't exist in the internal structure, `libseccomp` will refuse to create a filter for that. This happens with nixpkgs-23.11, i.e. on stable NixOS and when building Lix against the project's flake. To work around that * a backport of libseccomp 2.5.5 on upstream nixpkgs has been scheduled[3]. * the package now uses libseccomp 2.5.5 on its own already. This is to provide a quick fix since the correct fix for 23.11 is still a staging cycle away. We still need the compat header though since `SCMP_SYS(fchmodat2)` internally transforms this into `__SNR_fchmodat2` which points to `__NR_fchmodat2` from glibc 2.39, so it wouldn't build on glibc 2.38. The updated syscall table from libseccomp 2.5.5 is NOT used for that step, but used later, so we need both, our compat header and their syscall table 🤷 Relevant PRs in CppNix: * https://github.com/NixOS/nix/pull/10591 * https://github.com/NixOS/nix/pull/10501 [1] https://github.com/NixOS/nixpkgs/issues/300635#issuecomment-2031073804 [2] https://github.com/NixOS/nixpkgs/issues/300635#issuecomment-2030844251 [3] https://github.com/NixOS/nixpkgs/pull/306070 (cherry picked from commit ba6804518772e6afb403dd55478365d4b863c854) Change-Id: I6921ab5a363188c6bff617750d00bb517276b7fe
2024-05-03libstore: check additionalSandboxProfileArtemis Tosini
Currently LocalDerivationGoal allows setting `__sandboxProfile` to add sandbox parameters on Darwin when `sandbox=true`. This was only supposed to have an effect when `sandbox=relaxed` Change-Id: Ide44ee82d7e4d6b545285eab26547e7014817d3f
2024-04-27Run all derivation builders inside the sandbox on macOSPuck Meerburg
This replaces the external sandbox-exec call with direct calls into libsandbox. This API is technically deprecated and is missing some prototypes, but all major browsers depend on it, so it is unlikely to materially change without warning. This commit also ensures the netrc file is only written if the derivation is in fact meant to be able to access the internet. This change commits a sin of not actually actively declaring its dependency on macOS's libsandbox.dylib; this is due to the dylib cache in macOS making that explicit dependency unnecessary. In the future this might become a problem, so this commit marks our sins. Co-authored-by: Artemis Tosini <lix@artem.ist> Co-authored-by: Lunaphied <lunaphied@lunaphied.me> Change-Id: Ia302141a53ce7b0327c1aad86a117b6645fe1189
2024-04-16Merge "libstore/build: set NO_NEW_PRIVS for the sandbox" into mainIlya K
2024-04-15fix probable format bug in DerivationGoal::buildDoneQyriad
Either the contents of `line` could cause format errors, or this usage is Technically safe. However, I trust nothing, especially with boost::format. Change-Id: I07933b20bde3b305a6e5d61c2a7bab6ecb042ad9
2024-04-15libstore/build: set NO_NEW_PRIVS for the sandboxK900
Change-Id: I711f64e2b68495ed9c85c1a4bd5025405805e43a
2024-04-13libstore/build: just copy the magic /etc files into the sandboxK900
Saves us a bunch of thinking about how to handle symlinks, and prevents the DNS config from changing on the fly under the build, which may or may not be a good thing? Change-Id: I071e6ae7e220884690b788d94f480866f428db71
2024-04-11Merge pull request #10456 from NixOS/fixpermdeniedbindThéophane Hufschmitt
Fix adding symlink to the sandbox paths (cherry-picked from commit da1e977bf48cff2a635034c85e7c13878e38efc2) Change-Id: I221c85a38180800ec6552d2e86a88df48398fad8
2024-04-11Merge pull request #10362 from obsidiansystems/maybeLstatJohn Ericson
Factor out `nix::maybeLstat` (cherry-picked from commit 9b88e5284608116b7db0dbd3d5dd7a33b90d52d7) Change-Id: Id890525e847c890fad6593c594772826ac4d1d50
2024-03-31Merge changes Ib62d3d68,Ic3e7affe into mainjade
* changes: Make things that can throw not noexcept anymore Fix various clang-tidy lints
2024-03-29Add `pre-commit` checksRebecca Turner
The big ones here are `trim-trailing-whitespace` and `end-of-file-fixer` (which makes sure that every file ends with exactly one newline character). Change-Id: Idca73b640883188f068f9903e013cf0d82aa1123
2024-03-29Make things that can throw not noexcept anymoreJade Lovelace
This does involve making a large number of destructors able to throw, because we had to change it high in the class hierarchy. Oh well. Change-Id: Ib62d3d6895b755f20322bb8acc9bf43daf0174b2
2024-03-27HOT SALE: 15% off your build times!Jade Lovelace
This was achieved by running maintainers/buildtime_report.sh on the build directory of a meson build, then asking "why the heck is json eating our build times", and strategically moving the json using bits out of widely included headers. It turns out that putting literally any metrics whatsoever into the build had immediate and predictable results. Results are 1382.5s frontend time -> 1175.4s frontend time, back end time approximately invariant. Related: https://git.lix.systems/lix-project/lix/issues/159 Change-Id: I7edea95c8536203325c8bb4dae5f32d727a21b2d
2024-03-18libutil: make AutoCloseFD a better resourceeldritch horrors
add a reset() method to close the wrapped fd instead of assigning magic constants. also make the from-fd constructor explicit so you can't accidentally assign the *wrong* magic constant, or even an unrelated integer that also just happens to be an fd by pure chance. Change-Id: I51311b0f6e040240886b5103d39d1794a6acc325
2024-03-17Delete hasPrefix and hasSuffix from the codebaseJade Lovelace
These now have equivalents in the standard lib in C++20. This change was performed with a custom clang-tidy check which I will submit later. Executed like so: ninja -C build && run-clang-tidy -checks='-*,nix-*' -load=build/libnix-clang-tidy.so -p .. -fix ../tests | tee -a clang-tidy-result Change-Id: I62679e315ff9e7ce72a40b91b79c3e9fc01b27e9
2024-03-11util.hh: split out signals stuffJade Lovelace
Copies part of the changes of ac89bb064aeea85a62b82a6daf0ecca7190a28b7 Change-Id: I9ce601875cd6d4db5eb1132d7835c5bab9f126d8
2024-03-09Merge pull request #9925 from 9999years/fmt-cleanupeldritch horrors
Cleanup `fmt.hh` (cherry picked from commit 47a1dbb4b8e7913cbb9b4d604728b912e76e4ca0) Change-Id: Id076a45cb39652f437fe3f8bda10c310a9894777
2024-03-09libexpr: Support structured error classeseldritch horrors
While preparing PRs like #9753, I've had to change error messages in dozens of code paths. It would be nice if instead of EvalError("expected 'boolean' but found '%1%'", showType(v)) we could write TypeError(v, "boolean") or similar. Then, changing the error message could be a mechanical refactor with the compiler pointing out places the constructor needs to be changed, rather than the error-prone process of grepping through the codebase. Structured errors would also help prevent the "same" error from having multiple slightly different messages, and could be a first step towards error codes / an error index. This PR reworks the exception infrastructure in `libexpr` to support exception types with different constructor signatures than `BaseError`. Actually refactoring the exceptions to use structured data will come in a future PR (this one is big enough already, as it has to touch every exception in `libexpr`). The core design is in `eval-error.hh`. Generally, errors like this: state.error("'%s' is not a string", getAttrPathStr()) .debugThrow<TypeError>() are transformed like this: state.error<TypeError>("'%s' is not a string", getAttrPathStr()) .debugThrow() The type annotation has moved from `ErrorBuilder::debugThrow` to `EvalState::error`. (cherry picked from commit c6a89c1a1659b31694c0fbcd21d78a6dd521c732) Change-Id: Iced91ba4e00ca9e801518071fb43798936cbd05a
2024-03-06Merge pull request #9280 from R-VdP/rvdp/fix_remote_logging_phase_reportingeldritch horrors
Include phase reporting in log file for ssh-ng builds (cherry picked from commit b1e7d7cad625095656fff05ac4aedeb12135110a) Change-Id: I4076669b0ba160412f7c628ca9113f9abbc8c303
2024-03-07Copy the output of fixed-output derivations before registering themPuck Meerburg
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). 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. (cherry picked from commit 2dadfeb690e7f4b8f97298e29791d202fdba5ca6) (tests cherry picked from commit c854ae5b3078ac5d99fa75fe148005044809e18c) Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io> Co-authored-by: Theophane Hufschmitt <theophane.hufschmitt@tweag.io> Co-authored-by: Tom Bereknyei <tomberek@gmail.com> Change-Id: I87cd58f1c0a4f7b7a610d354206b33301e47b1a4
2024-03-04Merge pull request #9974 from edolstra/less-chatty-post-build-hookeldritch horrors
runPostBuildHook(): Be less chatty (cherry picked from commit 28a988bdde7b20abff9000162015500c44a5812b) Change-Id: Ibb49b71bf631d04d08970d719f091221b15c5036
2024-03-04Merge pull request #9924 from 9999years/rename-yellowtxteldritch horrors
Rename `yellowtxt` -> `magentatxt` (cherry picked from commit fb78a99e04206e7b1df84a362bb87d3300b41855) Change-Id: I9ade553d9f499e6713aeff3463c9a653a880a051
2024-03-04Merge pull request #9804 from edolstra/missing-nar-crasheldritch horrors
Fix crash when NAR is missing from binary cache (cherry picked from commit 3b20cca9625a1701a10a883735e7315185629563) Change-Id: I50ff18f4a6de69c323473b4a8e3e098d1f365145
2024-03-04Merge pull request #9797 from edolstra/fix-error-messageeldritch horrors
Store: :buildPaths(): Fix display of store paths (cherry picked from commit b5ed36e6633cac844fe4388dcc0cc8055a18ef9e) Change-Id: Ic6008491088dc6febd4a1e44dc2dbb96c47661f4
2024-03-04Merge pull request #9763 from L-as/avoid-unnecessary-copyeldritch horrors
Avoid unnecessary copy of goal log (cherry picked from commit 268c49264ae2657c602f84f9bff3eb31306253ea) Change-Id: I5d9de9e43a7ddcb09d25bbc7367c9d83f58c7a75
2024-03-04Merge pull request #9687 from edolstra/withFramedSink-ctrl-c-hangeldritch horrors
withFramedSink(): Receive interrupts on the stderr thread (cherry picked from commit 965cfe96886c988c3aa94bfc7fefdd37325f4536) Change-Id: I8320a96957c01ec0e3450d1b3ae38a3baff78d49
2024-03-04Merge pull request #9641 from amarshall/darwin-sandbox-stderreldritch horrors
Allow access to /dev/stderr in Darwin sandbox (cherry picked from commit c6d7013583c568590aff285fb7414d1675a745f4) Change-Id: I5657f6f4ee9dad8c978bad0d71f5cac51584e4f2
2024-03-04Merge pull request #9589 from ↵eldritch horrors
obsidiansystems/floating-content-addressing-derivations-eval-store Fix building CA derivations with and eval store (cherry picked from commit dfc0cee7024a082d90a4f68296f55a82dfd52126) Change-Id: I28feb5a36d4fe75f0ed3e3e2db6eb56b67d0f371
2024-03-04Merge pull request #9563 from obsidiansystems/tryResolve-evalStoreeldritch horrors
Give `Derivation::tryResolve` an `evalStore` argument (cherry picked from commit 36ca6adc60511dc822870f2df43c0a578e481925) Change-Id: If76b185a01ffa982e4c49cf333a9b5fbf9edebfe
2024-03-04Merge pull request #9400 from hercules-ci/refactors-from-5e3986f59cbeldritch horrors
Refactors from 5e3986f59cb (cherry picked from commit e540d48c4fb460e5e577d8b8b33e8eca9959c49b) Change-Id: I5b21b770a0c20ec2ec9845d3a97a524f1b0135ee
2024-03-04Merge pull request #6469 from gbpdt/fix/skipped_build_lockingeldritch horrors
Unlock output paths when a derivation is already built (cherry picked from commit 7ba4e073e8622ca86b52e03d68476e80250ab62f) Change-Id: I9de077679290d5141a610ac43d99d3a43acff87c
2024-03-04Merge pull request #9271 from keszybz/if-fixeldritch horrors
fix: gcc complains about if which doesn't guard the indented statement (cherry picked from commit 8d663462938a333a4e81cce1005437f141cd11fa) Change-Id: Ifa2e65502de4000935549dde82ab1b5867e2f0ed
2024-03-04Merge pull request #9246 from trofi/clarify-builder-uid-exhaustioneldritch horrors
local-derivation-goal.cc: slightly clarify waiting message (cherry picked from commit 232e23667226a3cfff9de1828f819844c27e7539) Change-Id: Idd271d6921caba203db9971f27e156e533664935
2024-03-04Merge pull request #8965 from Artturin/bindfilesinchrooteldritch horrors
Bindmount files instead of hardlinking or copying to chroot (cherry picked from commit 622191c2b53882a1675fed5066ff8090b4f01827) Change-Id: I278ec1baacdfa9044992b58fdec8f14d6d7d09ce
2024-03-04Merge pull request #9172 from tfc/bad-moveseldritch horrors
Fix/remove some bad std::moves (cherry picked from commit 8c049a9f044569ebda70231709f6f15d3073894a) Change-Id: I720273378d2506a13883acee28abd096d099b0d4